<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta property="og:type" content="website">
<meta property="og:title" content="kyssion-blog">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="kyssion-blog">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="kyssion-blog">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/"/>





  <title>kyssion-blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">kyssion-blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-schedule">
          <a href="/schedule/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-calendar"></i> <br />
            
            日程表
          </a>
        </li>
      
        
        <li class="menu-item menu-item-sitemap">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br />
            
            站点地图
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/深入理解mybatis（一）基础配置/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/深入理解mybatis（一）基础配置/" itemprop="url">深入理解mybatis(一) 基础配置</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:48:08+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/数据库/" itemprop="url" rel="index">
                    <span itemprop="name">数据库</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/数据库/orm框架/" itemprop="url" rel="index">
                    <span itemprop="name">orm框架</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/数据库/orm框架/mybatis/" itemprop="url" rel="index">
                    <span itemprop="name">mybatis</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="深入理解mybatis-一-基础配置"><a href="#深入理解mybatis-一-基础配置" class="headerlink" title="深入理解mybatis(一) 基础配置"></a>深入理解mybatis(一) 基础配置</h2><p>MyBatis 是一款优秀的持久层框架，它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息，将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。</p>
<h3 id="mybatis基础配置和使用"><a href="#mybatis基础配置和使用" class="headerlink" title="mybatis基础配置和使用"></a>mybatis基础配置和使用</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span><br><span class="line"><span class="meta">&lt;!DOCTYPE PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 使用配置信息可以在上下文中进行配置 这里配置的信息可以在上下中使用$&#123;xx&#125;访问到--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">properties</span> <span class="attr">resource</span>=<span class="string">"jdbc.properties"</span>&gt;</span><span class="comment">&lt;!-- 这里的第一句使用了配置文件属性这个属性会搜索一个属将配置信息传入进来效果和在文件中直接进行配置的方法是相同的 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"myproperty"</span> <span class="attr">value</span>=<span class="string">"123123"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- setting属性 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">settings</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 打印查询语句 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">setting</span> <span class="attr">name</span>=<span class="string">"logImpl"</span> <span class="attr">value</span>=<span class="string">"STDOUT_LOGGING"</span> /&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 只有这个最好用使用内置方法  打印SQL只需要加一个setting就可以了。 mybatis的日志打印方式比较多，SLF4J | LOG4J | LOG4J2 |</span></span><br><span class="line"><span class="comment">        JDK_LOGGING | COMMONS_LOGGING | STDOUT_LOGGING | NO_LOGGING，可以根据自己的需要进行配置 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 开启延迟加载 只用在使用的时候才进行数据库访问--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">setting</span> <span class="attr">name</span>=<span class="string">"lazyLoadingEnabled"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--</span></span><br><span class="line"><span class="comment">            属性true按照 层级加载（理解  就是按照第一次查询必须要出现的东西，就是第n次select可以查出的内容</span></span><br><span class="line"><span class="comment">            (discriminator属性和id result属性相同同)，false按照需求加载</span></span><br><span class="line"><span class="comment">        --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">setting</span> <span class="attr">name</span>=<span class="string">"aggressiveLazyloading"</span> <span class="attr">value</span>=<span class="string">"false"</span>&gt;</span><span class="tag">&lt;/<span class="name">setting</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 配置全局缓存的开关 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">setting</span> <span class="attr">name</span>=<span class="string">"cacheEnable"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 决定框架的延迟时间 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">setting</span> <span class="attr">name</span>=<span class="string">"defaultStatementTimeout"</span> <span class="attr">value</span>=<span class="string">"100"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--     其他相关的属性</span></span><br><span class="line"><span class="comment">        cacheEnabled				该配置影响的所有映射器中配置的缓存的全局开关。</span></span><br><span class="line"><span class="comment">                                    true | false	true</span></span><br><span class="line"><span class="comment">        lazyLoadingEnabled			延迟加载的全局开关。当开启时，所有关联对象都会延迟加载。</span></span><br><span class="line"><span class="comment">                                    特定关联关系中可通过设置fetchType属性来覆盖该项的开关状态.</span></span><br><span class="line"><span class="comment">                                    true | false	false</span></span><br><span class="line"><span class="comment">        aggressiveLazyLoading		当开启时，任何方法的调用都会加载该对象的所有属性。否则，每个属性会按需加载（参考lazyLoadTriggerMethods).</span></span><br><span class="line"><span class="comment">        multipleResultSetsEnabled	是否允许单一语句返回多结果集（需要兼容驱动）。</span></span><br><span class="line"><span class="comment">                                    true | false	true</span></span><br><span class="line"><span class="comment">        autoMappingBehavior			指定 MyBatis 应如何自动映射列到字段或属性。</span></span><br><span class="line"><span class="comment">                                    NONE 表示取消自动映射；PARTIAL 只会自动映射没有定义嵌套结果集映射的结果集。 FULL 会自动映射任意复杂的结果集（无论是否嵌套）。</span></span><br><span class="line"><span class="comment">                                    NONE,PARTIAL,FULL	PARTIAL</span></span><br><span class="line"><span class="comment">        defaultExecutorType			配置默认的执行器。SIMPLE 就是普通的执行器；REUSE 执行器会重用预处理语句（prepared statements）;BATCH 执行器将重用语句并执行批量更新.</span></span><br><span class="line"><span class="comment">                                    SIMPLE REUSE BATCH	SIMPLE</span></span><br><span class="line"><span class="comment">        defaultStatementTimeout		设置超时时间，它决定驱动等待数据库响应的秒数。</span></span><br><span class="line"><span class="comment">                                    任意正整数	Not Set (null)</span></span><br><span class="line"><span class="comment">        defaultFetchSize			为驱动的结果集获取数量（fetchSize）设置一个提示值。此参数只可以在查询设置中被覆盖。</span></span><br><span class="line"><span class="comment">                                    任意正整数	Not Set (null)</span></span><br><span class="line"><span class="comment">        safeRowBoundsEnabled		允许在嵌套语句中使用分页（RowBounds）。 If allow, set the false.</span></span><br><span class="line"><span class="comment">                                    true | false	False</span></span><br><span class="line"><span class="comment">        safeResultHandlerEnabled	允许在嵌套语句中使用分页（ResultHandler）。 If allow, set the false.</span></span><br><span class="line"><span class="comment">                                    true | false	True</span></span><br><span class="line"><span class="comment">        mapUnderscoreToCamelCase	是否开启自动驼峰命名规则（camel case）映射，即从经典数据库列名 A_COLUMN 到经典 Java 属性名 aColumn 的类似映射。</span></span><br><span class="line"><span class="comment">                                    true | false	False</span></span><br><span class="line"><span class="comment">        localCacheScope	MyBatis 	利用本地缓存机制（Local Cache）防止循环引用（circular references）和加速重复嵌套查询。</span></span><br><span class="line"><span class="comment">                                    默认值为 SESSION，这种情况下会缓存一个会话中执行的所有查询。</span></span><br><span class="line"><span class="comment">                                    若设置值为 STATEMENT，本地会话仅用在语句执行上，对相同 SqlSession 的不同调用将不会共享数据。</span></span><br><span class="line"><span class="comment">                                    SESSION | STATEMENT	SESSION</span></span><br><span class="line"><span class="comment">        jdbcTypeForNull				当没有为参数提供特定的 JDBC 类型时，为空值指定 JDBC 类型。</span></span><br><span class="line"><span class="comment">                                    某些驱动需要指定列的 JDBC 类型，多数情况直接用一般类型即可，比如 NULL、VARCHAR 或 OTHER。</span></span><br><span class="line"><span class="comment">                                    JdbcType enumeration. Most common are: NULL, VARCHAR and OTHER	OTHER</span></span><br><span class="line"><span class="comment">        lazyLoadTriggerMethods		指定哪个对象的方法触发一次延迟加载。</span></span><br><span class="line"><span class="comment">                                    A method name list separated by commas	equals,clone,hashCode,toString</span></span><br><span class="line"><span class="comment">        defaultScriptingLanguage	指定动态 SQL 生成的默认语言。	A type alias or fully qualified class name.</span></span><br><span class="line"><span class="comment">                                    org.apache.ibatis.scripting.xmltags.XMLLanguageDriver</span></span><br><span class="line"><span class="comment">        callSettersOnNulls			指定当结果集中值为 null 的时候是否调用映射对象的 setter（map 对象时为 put）方法，</span></span><br><span class="line"><span class="comment">                                    这对于有 Map.keySet() 依赖或 null 值初始化的时候是有用的。注意基本类型（int、boolean等）是不能设置成 null 的。</span></span><br><span class="line"><span class="comment">                                    true | false	false</span></span><br><span class="line"><span class="comment">        logPrefix					指定 MyBatis 增加到日志名称的前缀。</span></span><br><span class="line"><span class="comment">                                    Any String	Not set</span></span><br><span class="line"><span class="comment">        logImpl						指定 MyBatis 所用日志的具体实现，未指定时将自动查找。</span></span><br><span class="line"><span class="comment">                                    SLF4J | LOG4J | LOG4J2 | JDK_LOGGING | COMMONS_LOGGING | STDOUT_LOGGING | NO_LOGGING	Not set</span></span><br><span class="line"><span class="comment">         --&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">settings</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 别名:在系统的其他位置上可以用这个别名进行配置文件的配置 两种方法只能用一种 原因 文件只进行扫描一遍--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">typeAliases</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 1.可以使用注解方法进行配置 Alias注解方法 name为将要进行扫描的包  使用的时候自动为相关的类添加上相关的包名称，但是要注意冲突的问题 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">package</span> <span class="attr">name</span>=<span class="string">"javabean"</span>/&gt;</span><span class="comment">&lt;!-- 如果使用这个中方法将会自动将这个包下面直接的javabean 按照小写字母映射 不能和下面的方法共存 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 直接在这里面进行配置type是属性的全名称 alias 是别名称 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">typeAlias</span> <span class="attr">type</span>=<span class="string">"S_Mybatis.a_自定义typeHandler.自定义typeHandler"</span> <span class="attr">alias</span>=<span class="string">"mytypehandle"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">typeAliases</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--格式转换器 定义的转换器 可以完成java类型和jdbc类型的自动转换  一般用来自己重写数据库的映射方法--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">typeHandlers</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">typeHandler</span> <span class="attr">handler</span>=<span class="string">"S_Mybatis.a_自定义typeHandler.自定义typeHandler"</span> <span class="attr">javaType</span>=<span class="string">"string"</span> <span class="attr">jdbcType</span>=<span class="string">"VARCHAR"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">package</span> <span class="attr">name</span>=<span class="string">"S_Mybatis.a_自定义typeHandler"</span>/&gt;</span><span class="comment">&lt;!-- 使用注解方法加载包 自动加入对应包中有属性的名称使用xml的定义式 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">typeHandlers</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">objectFactory</span> <span class="attr">type</span>=<span class="string">"S_Mybatis.b_自定义工厂方法.Myfactory"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"name"</span> <span class="attr">value</span>=<span class="string">"b_自定义工厂方法"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">objectFactory</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 数据库环境标签 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">environments</span> <span class="attr">default</span>=<span class="string">"myenviroment"</span>&gt;</span><span class="comment">&lt;!-- 这个属性表明在环境变量缺省的情况下启用哪个标签 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 配置一个数据源的开始 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">environment</span> <span class="attr">id</span>=<span class="string">"myenviroment"</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!-- 数据库事务配置 (一般使用spring框架进行控制 之后再说)1.jdbc 2.MANAGEN(JNDI数据源中的相关事务)3.自定义 --&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">transactionManager</span> <span class="attr">type</span>=<span class="string">"JDBC"</span>&gt;</span><span class="tag">&lt;/<span class="name">transactionManager</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!-- 配置数据连接信息1.UNPOOLED非连接池数据库2.POOLED链接池数据库3.JNDI 4.自定义  --&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">dataSource</span> <span class="attr">type</span>=<span class="string">"UNPOOLED"</span>&gt;</span></span><br><span class="line">                <span class="comment">&lt;!-- 针对 pooled属性的：</span></span><br><span class="line"><span class="comment">                    poolMaximumActiveConnections 	– 在任意时间可以存在的活动（也就是正在使用）连接数量，默认值：10</span></span><br><span class="line"><span class="comment">                    poolMaximumIdleConnections 		– 任意时间可能存在的空闲连接数。</span></span><br><span class="line"><span class="comment">                    poolMaximumCheckoutTime			– 在被强制返回之前，池中连接被检出（checked out）时间，默认值：20000 毫秒（即 20 秒）</span></span><br><span class="line"><span class="comment">                    poolTimeToWait 					– 这是一个底层设置，如果获取连接花费的相当长的时间，</span></span><br><span class="line"><span class="comment">                                                    - 它会给连接池打印状态日志并重新尝试获取一个连接（避免在误配置的情况下一直安静的失败），</span></span><br><span class="line"><span class="comment">                                                    - 默认值：20000 毫秒（即 20 秒）。</span></span><br><span class="line"><span class="comment">                    poolPingQuery 					– 发送到数据库的侦测查询，用来检验连接是否处在正常工作秩序中并准备接受请求。</span></span><br><span class="line"><span class="comment">                                                    - 默认是“NO PING QUERY SET”，这会导致多数数据库驱动失败时带有一个恰当的错误消息。</span></span><br><span class="line"><span class="comment">                    poolPingEnabled 				– 是否启用侦测查询。若开启，也必须使用一个可执行的 SQL 语句设置 poolPingQuery 属性（最好是一个非常快的 SQL），</span></span><br><span class="line"><span class="comment">                                                    - 默认值：false。</span></span><br><span class="line"><span class="comment">                    poolPingConnectionsNotUsedFor 	– 配置 poolPingQuery 的使用频度。这可以被设置成匹配具体的数据库连接超时时间，来避免不必要的侦测，</span></span><br><span class="line"><span class="comment">                                                    - 默认值：0（即所有连接每一时刻都被侦测 — 当然仅当 poolPingEnabled 为 true 时适用）。</span></span><br><span class="line"><span class="comment">                 --&gt;</span></span><br><span class="line">                <span class="comment">&lt;!-- 使用 ognl表达式的$&#123;&#125;形式加入参数 --&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"driver"</span> <span class="attr">value</span>=<span class="string">"$&#123;properties_driver&#125;"</span> /&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"url"</span> <span class="attr">value</span>=<span class="string">"jdbc:mysql://127.0.0.1:3306/mybatis"</span> /&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"username"</span> <span class="attr">value</span>=<span class="string">"$&#123;properties_user&#125;"</span> /&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"password"</span> <span class="attr">value</span>=<span class="string">"14159265jkl"</span> /&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">dataSource</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!-- 数据库事务 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">environment</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">environments</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- mybatis数据库厂商标识 db_vendor 使用数据库默认规则-首先mybatis会将配置读入configuration中</span></span><br><span class="line"><span class="comment">    在连接数据库后调用getDatabaseProductName（）方法获取数据库的信息，然后配置name值去做匹配来得到databaseid  --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">databaseIdProvider</span> <span class="attr">type</span>=<span class="string">"DB_VENDOR"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"SQL Server"</span> <span class="attr">value</span>=<span class="string">"sqlserver"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"DB2"</span> <span class="attr">value</span>=<span class="string">"db2"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"Oracle"</span> <span class="attr">value</span>=<span class="string">"oracle"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">databaseIdProvider</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 定义mybatis使用的映射文件 !!!!!注意这里非常容易出现错误 要使用的文件mapping一定要在这里面进行配置--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mappers</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">mapper</span> <span class="attr">resource</span>=<span class="string">"mapper_WaiLianJie.xml"</span>/&gt;</span><span class="comment">&lt;!-- 使用文件进行引入 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--&lt;mapper class="com.dao.mapper_SqlQianTao"/&gt;--&gt;</span><span class="comment">&lt;!-- 使用class文件进行引入 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--貌似不能和mapper共存&lt;package name="com.dao"/&gt;使用报名进行引入--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">mapper</span> <span class="attr">url</span>=<span class="string">"file:///var/mappers/AuthorMapper.xml"</span>/&gt;</span><span class="comment">&lt;!-- 使用url进行引用 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">mappers</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="相关标签注意事项"><a href="#相关标签注意事项" class="headerlink" title="相关标签注意事项"></a>相关标签注意事项</h3><h4 id="typeAliases-别名配置引申"><a href="#typeAliases-别名配置引申" class="headerlink" title="typeAliases 别名配置引申"></a>typeAliases 别名配置引申</h4><p>如果使用package的标签的时候将会使用将类名首字母小写和对应的对象完整类名映射，可以通过@Alias(name) 注解来更改映射的规则</p>
<h4 id="properties标签除了使用xml进行相关属性配置，还可以使用java-api的形式可以使用如下的方法进行配置"><a href="#properties标签除了使用xml进行相关属性配置，还可以使用java-api的形式可以使用如下的方法进行配置" class="headerlink" title="properties标签除了使用xml进行相关属性配置，还可以使用java api的形式可以使用如下的方法进行配置"></a>properties标签除了使用xml进行相关属性配置，还可以使用java api的形式可以使用如下的方法进行配置</h4><blockquote>
<p>使用java代码动态的导入属性</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"><span class="keyword">import</span> java.util.Properties;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.io.Resources;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.session.SqlSessionFactory;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.session.SqlSessionFactoryBuilder;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Mybatis</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        InputStream inputStream=<span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            inputStream = Resources.getResourceAsStream(<span class="string">"xxxx.xml"</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            <span class="comment">// TODO Auto-generated catch block</span></span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        Properties properties = <span class="keyword">new</span> Properties();</span><br><span class="line">        properties.setProperty(<span class="string">"username"</span>, <span class="string">"root"</span>);</span><br><span class="line">        properties.setProperty(<span class="string">"password"</span>, <span class="string">"14159265jkl"</span>);</span><br><span class="line">        SqlSessionFactory sessionFactory=<span class="keyword">new</span> SqlSessionFactoryBuilder().build(inputStream, properties);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>如果属性在不只一个地方进行了配置，那么 MyBatis 将按照下面的顺序来加载：</p>
<ol>
<li>在 properties 元素体内指定的属性首先被读取。</li>
<li>然后根据 properties 元素中的 resource 属性读取类路径下属性文件或根据 url 属性指定的路径读取属性文件，并覆盖已读取的同名属性。</li>
<li>最后读取作为方法参数传递的属性，并覆盖已读取的同名属性。</li>
</ol>
<ul>
<li>因此，通过方法参数传递的属性具有最高优先级，resource/url 属性中指定的配置文件次之，最低优先级的是 properties 属性中指定的属性。</li>
</ul>
<blockquote>
<p>使用输入流进行构建</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.io.Resources;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.session.SqlSessionFactory;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.session.SqlSessionFactoryBuilder;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Mybatis</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        String resource = <span class="string">"mybatis-config.xml"</span>;</span><br><span class="line">        InputStream inputStream=<span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            inputStream = Resources.getResourceAsStream(resource);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        SqlSessionFactory sessionFactory =<span class="keyword">new</span> SqlSessionFactoryBuilder().build(inputStream);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="typeHandlers-重写类型处理器或创建你自己的类型处理器来处理不支持的或非标准的类型"><a href="#typeHandlers-重写类型处理器或创建你自己的类型处理器来处理不支持的或非标准的类型" class="headerlink" title="typeHandlers-重写类型处理器或创建你自己的类型处理器来处理不支持的或非标准的类型"></a>typeHandlers-重写类型处理器或创建你自己的类型处理器来处理不支持的或非标准的类型</h4><p>具体做法为：实现 org.apache.ibatis.type.TypeHandler 接口， 或继承一个很便利的类 org.apache.ibatis.type.BaseTypeHandler， 然后可以选择性地将它映射到一个 JDBC 类型。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.sql.CallableStatement;</span><br><span class="line"><span class="keyword">import</span> java.sql.PreparedStatement;</span><br><span class="line"><span class="keyword">import</span> java.sql.ResultSet;</span><br><span class="line"><span class="keyword">import</span> java.sql.SQLException;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.type.BaseTypeHandler;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.type.JdbcType;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.type.MappedJdbcTypes;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.type.MappedTypes;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.type.TypeHandler;</span><br><span class="line"><span class="comment">//!--注意若果使用了注解就可以在配置文件中使用pagexx的属性而不用使用typeHandler属性</span></span><br><span class="line"><span class="meta">@MappedTypes</span>(&#123; String.class &#125;) <span class="comment">// 定义数据库映射的的java属性 指定那些类型将会被拦截</span></span><br><span class="line"><span class="meta">@MappedJdbcTypes</span>(JdbcType.VARCHAR) <span class="comment">// 定义数据库映射数据库的类型</span></span><br><span class="line"><span class="comment">// 当使用自定义typeHandle的时候需要实现这个接口</span></span><br><span class="line"><span class="comment">// !---在mapping文件中需要显示的注册使用的tylehandle 并且在mybatis的配置文件(和mapping文集不同)文件中个必须进行注册</span></span><br><span class="line"><span class="comment">//注意 MappedJdbcTypes这个注解还有一个属性 includeNullJdbcType=true 默认值为false 表示当在只使用时-</span></span><br><span class="line"><span class="comment">//-只指定了javaType类型但是没有指定 jdbctype的时候同样可以使用这个映射</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> 自定义<span class="title">typeHandler</span> <span class="keyword">implements</span> <span class="title">TypeHandler</span>&lt;<span class="title">String</span>&gt; </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getResult</span><span class="params">(ResultSet arg0, String columeName)</span> <span class="keyword">throws</span> SQLException </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getResult</span><span class="params">(ResultSet arg0, <span class="keyword">int</span> index)</span> <span class="keyword">throws</span> SQLException </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getResult</span><span class="params">(CallableStatement arg0, <span class="keyword">int</span> arg1)</span> <span class="keyword">throws</span> SQLException </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setParameter</span><span class="params">(PreparedStatement arg0, <span class="keyword">int</span> arg1, String arg2, JdbcType arg3)</span> <span class="keyword">throws</span> SQLException </span>&#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//还可以使用相关的抽象类进行实现</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MytypeHandler2</span> <span class="keyword">extends</span> <span class="title">BaseTypeHandler</span>&lt;<span class="title">String</span>&gt;</span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getNullableResult</span><span class="params">(ResultSet arg0, String arg1)</span> <span class="keyword">throws</span> SQLException </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getNullableResult</span><span class="params">(ResultSet arg0, <span class="keyword">int</span> arg1)</span> <span class="keyword">throws</span> SQLException </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getNullableResult</span><span class="params">(CallableStatement arg0, <span class="keyword">int</span> arg1)</span> <span class="keyword">throws</span> SQLException </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setNonNullParameter</span><span class="params">(PreparedStatement arg0, <span class="keyword">int</span> arg1, String arg2, JdbcType arg3)</span> <span class="keyword">throws</span> SQLException </span>&#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>mybatis在使用自定义的type的时候，需要在结果属性（resultMap中的property或者id属性中）使用javatype和JDBCtype属性进行相关联，或者直接指定typehandler</strong></p>
<h4 id="枚举类型的特殊处理"><a href="#枚举类型的特殊处理" class="headerlink" title="枚举类型的特殊处理"></a>枚举类型的特殊处理</h4><p>若想映射枚举类型 Enum，则需要从 EnumTypeHandler 或者 EnumOrdinalTypeHandler 中选一个来使用。默认情况下，MyBatis 会利用 EnumTypeHandler 来把 Enum 值转换成对应的名字。</p>
<blockquote>
<p>注意 EnumTypeHandler 在某种意义上来说是比较特别的，其他的处理器只针对某个特定的类，而它不同，它会处理任意继承了 Enum 的类。</p>
</blockquote>
<p>自动映射器（auto-mapper）会自动地选用 EnumOrdinalTypeHandler 来处理， 所以如果我们想用普通的 EnumTypeHandler，就必须要显式地为那些 SQL 语句设置要使用的类型处理器。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"org.apache.ibatis.submitted.rounding.User"</span> <span class="attr">id</span>=<span class="string">"usermap2"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">id</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">property</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"name"</span> <span class="attr">property</span>=<span class="string">"name"</span>/&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"funkyNumber"</span> <span class="attr">property</span>=<span class="string">"funkyNumber"</span>/&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"roundingMode"</span> <span class="attr">property</span>=<span class="string">"roundingMode"</span> <span class="attr">typeHandler</span>=<span class="string">"org.apache.ibatis.type.EnumTypeHandler"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"getUser2"</span> <span class="attr">resultMap</span>=<span class="string">"usermap2"</span>&gt;</span></span><br><span class="line">	select * from users2</span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">"insert2"</span>&gt;</span></span><br><span class="line">    insert into users2 (id, name, funkyNumber, roundingMode) values (</span><br><span class="line">    	#&#123;id&#125;, #&#123;name&#125;, #&#123;funkyNumber&#125;, #&#123;roundingMode, typeHandler=org.apache.ibatis.type.EnumTypeHandler&#125;</span><br><span class="line">    )</span><br><span class="line"><span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="objectFactory-覆盖对象工厂的默认行为，创建自己的对象工厂。"><a href="#objectFactory-覆盖对象工厂的默认行为，创建自己的对象工厂。" class="headerlink" title="objectFactory-覆盖对象工厂的默认行为，创建自己的对象工厂。"></a>objectFactory-覆盖对象工厂的默认行为，创建自己的对象工厂。</h4><p>MyBatis 每次创建结果对象的新实例时，它都会使用一个对象工厂（ObjectFactory）实例来完成。 </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> java.util.Properties;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.reflection.factory.DefaultObjectFactory;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Myfactory</span> <span class="keyword">extends</span> <span class="title">DefaultObjectFactory</span></span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">long</span> serialVersionUID = <span class="number">1L</span>;</span><br><span class="line">    <span class="keyword">public</span> &lt;T&gt; <span class="function">T <span class="title">create</span><span class="params">(Class&lt;T&gt; type, List&lt;Class&lt;?&gt;&gt; constructorArgTypes, List&lt;Object&gt; constructorArgs)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">super</span>.create(type, constructorArgTypes, constructorArgs);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> &lt;T&gt; <span class="function">T <span class="title">create</span><span class="params">(Class&lt;T&gt; type)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">super</span>.create(type);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> &lt;T&gt; <span class="function"><span class="keyword">boolean</span> <span class="title">isCollection</span><span class="params">(Class&lt;T&gt; type)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">super</span>.isCollection(type);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">protected</span> Class&lt;?&gt; resolveInterface(Class&lt;?&gt; arg0) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">super</span>.resolveInterface(arg0);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setProperties</span><span class="params">(Properties properties)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>.setProperties(properties);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="plugins-MyBatis-允许你在已映射语句执行过程中的某一点进行拦截调用"><a href="#plugins-MyBatis-允许你在已映射语句执行过程中的某一点进行拦截调用" class="headerlink" title="plugins-MyBatis 允许你在已映射语句执行过程中的某一点进行拦截调用"></a>plugins-MyBatis 允许你在已映射语句执行过程中的某一点进行拦截调用</h4><p>默认情况下，MyBatis 允许使用插件来拦截的方法调用包括（格式：类名称（类下的方法））：</p>
<ul>
<li>Executor (update, query, flushStatements, commit, rollback, getTransaction, close, isClosed)</li>
<li>ParameterHandler (getParameterObject, setParameters)</li>
<li>ResultSetHandler (handleResultSets, handleOutputParameters)</li>
<li>StatementHandler (prepare, parameterize, batch, update, query)</li>
</ul>
<p>通过 MyBatis 提供的强大机制，使用插件是非常简单的，只需实现 Interceptor 接口，并指定了想要拦截的方法签名即可</p>
<blockquote>
<p>下面的插件将会拦截在 Executor 实例中所有的 “update” 方法调用， 这里的 Executor 是负责执行低层映射语句的内部对象。<strong>注意@Intercepts注解</strong></p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.Properties;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.executor.Executor;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.mapping.MappedStatement;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.plugin.Interceptor;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.plugin.Intercepts;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.plugin.Invocation;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.plugin.Signature;</span><br><span class="line"><span class="meta">@Intercepts</span>(&#123;<span class="meta">@Signature</span>(</span><br><span class="line">        type= Executor.class,</span><br><span class="line">        method = <span class="string">"update"</span>,</span><br><span class="line">        args = &#123;MappedStatement.class,Object.class&#125;)&#125;)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ExamplePlugin</span> <span class="keyword">implements</span> <span class="title">Interceptor</span></span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">intercept</span><span class="params">(Invocation arg0)</span> <span class="keyword">throws</span> Throwable </span>&#123;</span><br><span class="line">        <span class="comment">// TODO Auto-generated method stub</span></span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">plugin</span><span class="params">(Object arg0)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// TODO Auto-generated method stub</span></span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setProperties</span><span class="params">(Properties arg0)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// TODO Auto-generated method stub</span></span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="environments-MyBatis可以通过这个配置项配置成适应多种环境"><a href="#environments-MyBatis可以通过这个配置项配置成适应多种环境" class="headerlink" title="environments-MyBatis可以通过这个配置项配置成适应多种环境"></a>environments-MyBatis可以通过这个配置项配置成适应多种环境</h4><p>这种机制有助于将 SQL 映射应用于多种数据库之中， 现实情况下有多种理由需要这么做。例如，开发、测试和生产环境需要有不同的配置；或者共享相同 Schema 的多个生产数据库， 想使用相同的 SQL 映射。许多类似的用例。</p>
<blockquote>
<p>不过要记住：尽管可以配置多个环境，每个 SqlSessionFactory 实例只能选择其一。为了指定创建哪种环境，只要将它作为可选的参数传递给 SqlSessionFactoryBuilder 即可</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">SqlSessionFactory sessionFactory=<span class="keyword">new</span> SqlSessionFactoryBuilder().build(inputStream,<span class="string">"envoirment"</span>);</span><br><span class="line">SqlSessionFactory factory = <span class="keyword">new</span> SqlSessionFactoryBuilder().build(reader, environment);</span><br><span class="line">SqlSessionFactory factory = <span class="keyword">new</span> SqlSessionFactoryBuilder().build(reader, environment,properties);</span><br></pre></td></tr></table></figure>
<p>在环境配置中有两个重要的配置一个是事务管理器transactionManager，另一个是数据源dataSource （具体的配置信息可以参考之前使用的xml 配置方法）</p>
<blockquote>
<p>transactionManager事务管理器<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">TransactionFactory</span> </span>&#123;</span><br><span class="line">  <span class="function"><span class="keyword">void</span> <span class="title">setProperties</span><span class="params">(Properties props)</span></span>;  </span><br><span class="line">  <span class="function">Transaction <span class="title">newTransaction</span><span class="params">(Connection conn)</span></span>;</span><br><span class="line">  <span class="function">Transaction <span class="title">newTransaction</span><span class="params">(DataSource dataSource, TransactionIsolationLevel level, <span class="keyword">boolean</span> autoCommit)</span></span>;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
</blockquote>
<p>任何在 XML 中配置的属性在实例化之后将会被传递给 setProperties() 方法。你也需要创建一个 Transaction 接口的实现类，这个接口也很简单：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">Transaction</span> </span>&#123;</span><br><span class="line">  <span class="function">Connection <span class="title">getConnection</span><span class="params">()</span> <span class="keyword">throws</span> SQLException</span>;</span><br><span class="line">  <span class="function"><span class="keyword">void</span> <span class="title">commit</span><span class="params">()</span> <span class="keyword">throws</span> SQLException</span>;</span><br><span class="line">  <span class="function"><span class="keyword">void</span> <span class="title">rollback</span><span class="params">()</span> <span class="keyword">throws</span> SQLException</span>;</span><br><span class="line">  <span class="function"><span class="keyword">void</span> <span class="title">close</span><span class="params">()</span> <span class="keyword">throws</span> SQLException</span>;</span><br><span class="line">  <span class="function">Integer <span class="title">getTimeout</span><span class="params">()</span> <span class="keyword">throws</span> SQLException</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="databaseIdProvider"><a href="#databaseIdProvider" class="headerlink" title="databaseIdProvider"></a>databaseIdProvider</h4><p>MyBatis 可以根据不同的数据库厂商执行不同的语句，这种多厂商的支持是基于映射语句中的 databaseId 属性。 MyBatis 会加载不带 databaseId 属性和带有匹配当前数据库 databaseId 属性的所有语句。 如果同时找到带有 databaseId 和不带 databaseId 的相同语句，则后者会被舍弃。 </p>
<h4 id="mappers表示映射器"><a href="#mappers表示映射器" class="headerlink" title="mappers表示映射器"></a>mappers表示映射器</h4><p>注意：一个config文件可以导入多个配置文件   可以使用url地址或者resource 引入配置文件或者 使用包名称或者class文件</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">mappers</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mapper</span> <span class="attr">resource</span>=<span class="string">"mapper_WaiLianJie.xml"</span>/&gt;</span><span class="comment">&lt;!-- 使用文件进行引入 --&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--&lt;mapper class="com.dao.mapper_SqlQianTao"/&gt;--&gt;</span><span class="comment">&lt;!-- 使用class文件进行引入 --&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--貌似不能和mapper共存&lt;package name="com.dao"/&gt;使用报名进行引入--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mapper</span> <span class="attr">url</span>=<span class="string">"file:///var/mappers/AuthorMapper.xml"</span>/&gt;</span><span class="comment">&lt;!-- 使用url进行引用 --&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mappers</span>&gt;</span></span><br></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/test-1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/test-1/" itemprop="url">test</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:48:08+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/深入springboot-导入资源文件增强/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/深入springboot-导入资源文件增强/" itemprop="url">未命名</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:22:37+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="深入springboot-导入资源文件增强"><a href="#深入springboot-导入资源文件增强" class="headerlink" title="深入springboot-导入资源文件增强"></a>深入springboot-导入资源文件增强</h2><p>spring boot 通过注解的方法将各种属性通过自动化的形式加载进javabean中，简化操作。<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@PropertySource</span>(&#123;<span class="string">"classpath:application.yaml"</span>,<span class="string">"classpath:application.properties"</span>&#125;)</span><br><span class="line"><span class="meta">@ConfigurationProperties</span>(prefix = <span class="string">"auther"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MydemoApplication</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">getName</span><span class="params">()</span> </span>&#123;</span><br><span class="line">		<span class="keyword">return</span> name;</span><br><span class="line">	&#125;</span><br><span class="line"> </span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setName</span><span class="params">(String name)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">this</span>.name = name;</span><br><span class="line">	&#125;</span><br><span class="line"> </span><br><span class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">getPassword</span><span class="params">()</span> </span>&#123;</span><br><span class="line">		<span class="keyword">return</span> password;</span><br><span class="line">	&#125;</span><br><span class="line"> </span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setPassword</span><span class="params">(String password)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">this</span>.password = password;</span><br><span class="line">	&#125;</span><br><span class="line"> </span><br><span class="line">	<span class="keyword">private</span> String name;</span><br><span class="line">	<span class="keyword">private</span> String password;</span><br><span class="line">	<span class="meta">@RequestMapping</span>(<span class="string">"/"</span>)</span><br><span class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">say</span><span class="params">()</span></span>&#123;</span><br><span class="line">		System.out.println(<span class="keyword">this</span>.name+<span class="string">" :"</span>+<span class="keyword">this</span>.password);</span><br><span class="line">		<span class="keyword">return</span> <span class="keyword">this</span>.name+<span class="string">" :"</span>+<span class="keyword">this</span>.password;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		SpringApplication.run(MydemoApplication.class, args);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>配置文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">auther.name=liyuelin</span><br><span class="line">auther.password=14159265jkl</span><br></pre></td></tr></table></figure>
<p>@ConfigurationProperties注解将会对 自动注入相关配置文件中的属性省去 前缀自动的注入到相关的配置文件中</p>
<p>升级版注解  @EnableConfigurationProperties(MyconfigProperties.class)  一般结合 @configuration注解使用    —-将指定的类似上面javabean的bean 自动完成属性注入功能</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableConfigurationProperties</span>(MyconfigProperties.class)<span class="comment">//允许这个类进行自动转配并且导入配置文件属性</span></span><br><span class="line"><span class="meta">@EnableAspectJAutoProxy</span></span><br><span class="line"><span class="meta">@EnableAutoConfiguration</span></span><br><span class="line"><span class="meta">@ConfigurationProperties</span></span><br><span class="line"> </span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyconfigAutoConfig</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/spring扩展(二)application（集装箱扩展）/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/spring扩展(二)application（集装箱扩展）/" itemprop="url">未命名</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:22:37+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/算法阶段性小结(二)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/算法阶段性小结(二)/" itemprop="url">未命名</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:22:37+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="1-两数之和"><a href="#1-两数之和" class="headerlink" title="1. 两数之和"></a>1. 两数之和</h3><p>给定一个整数数组和一个目标值，找出数组中和为目标值的两个数。<br>你可以假设每个输入只对应一种答案，且同样的元素不能被重复利用。</p>
<p>这题我用了点类似背包问题的思想，总值为k 当前值为n 那么只要判断k-n 这个直在不在就行了，hashmap解决</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>&#123;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">int</span>[] twoSum(<span class="keyword">int</span>[] nums, <span class="keyword">int</span> target) &#123;</span><br><span class="line">        HashMap&lt;Integer,Integer&gt; hashMap = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> a=<span class="number">0</span>;a&lt;nums.length;a++)&#123;</span><br><span class="line">            hashMap.put(nums[a],a);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">int</span>[] need = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">2</span>];</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a=<span class="number">0</span>;a&lt;nums.length;a++)&#123;</span><br><span class="line">            <span class="keyword">int</span> end = target-nums[a];</span><br><span class="line">            <span class="keyword">if</span> (hashMap.get(end)!=<span class="keyword">null</span>&amp;&amp;hashMap.get(end)&gt;a)&#123;</span><br><span class="line">                need[<span class="number">0</span>]=a;</span><br><span class="line">                need[<span class="number">1</span>]=hashMap.get(end);</span><br><span class="line">                <span class="keyword">return</span> need;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> need;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="2-两数相加"><a href="#2-两数相加" class="headerlink" title="2. 两数相加"></a>2. 两数相加</h3><p>给定两个非空链表来表示两个非负整数。位数按照逆序方式存储，它们的每个节点只存储单个数字。将两数相加返回一个新的链表。</p>
<p>你可以假设除了数字 0 之外，这两个数字都不会以零开头。</p>
<p>示例：</p>
<p>输入：(2 -&gt; 4 -&gt; 3) + (5 -&gt; 6 -&gt; 4)<br>输出：7 -&gt; 0 -&gt; 8<br>原因：342 + 465 = 807</p>
<p>没什么java 链表基础，注意java中没有变量的变量</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Code02</span> </span>&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> jin;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> ListNode <span class="title">createNextNode</span><span class="params">(<span class="keyword">int</span> l1, <span class="keyword">int</span> l2, ListNode before)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> number = l1 + l2 + jin;</span><br><span class="line">        jin = number / <span class="number">10</span>;</span><br><span class="line">        number = number % <span class="number">10</span>;</span><br><span class="line">        ListNode nowNode = <span class="keyword">new</span> ListNode(number);</span><br><span class="line">        <span class="keyword">if</span> (before != <span class="keyword">null</span>) &#123;</span><br><span class="line">            before.next = nowNode;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            end = nowNode;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> nowNode;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> ListNode end = <span class="keyword">null</span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> ListNode <span class="title">addTwoNumbers</span><span class="params">(ListNode l1, ListNode l2)</span> </span>&#123;</span><br><span class="line">        ListNode before = <span class="keyword">null</span>;</span><br><span class="line">        jin = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> number1 = l1.val;</span><br><span class="line">        <span class="keyword">int</span> number2 = l2.val;</span><br><span class="line">        <span class="keyword">do</span> &#123;</span><br><span class="line">            before = createNextNode(number1, number2, before);</span><br><span class="line">            <span class="keyword">if</span> (l1 != <span class="keyword">null</span>) &#123;</span><br><span class="line">                l1 = l1.next;</span><br><span class="line">                number1 = l1 == <span class="keyword">null</span> ? <span class="number">0</span> : l1.val;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (l2 != <span class="keyword">null</span>) &#123;</span><br><span class="line">                l2 = l2.next;</span><br><span class="line">                number2 = l2 == <span class="keyword">null</span> ? <span class="number">0</span> : l2.val;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">while</span> (l1 != <span class="keyword">null</span> || l2 != <span class="keyword">null</span>);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (jin &gt; <span class="number">0</span>) &#123;</span><br><span class="line">            ListNode listNode = <span class="keyword">new</span> ListNode(jin);</span><br><span class="line">            before.next = listNode;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> end;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="3-无重复字符的最长子串"><a href="#3-无重复字符的最长子串" class="headerlink" title="3. 无重复字符的最长子串"></a>3. 无重复字符的最长子串</h3><p>给定一个字符串，找出不含有重复字符的最长子串的长度。</p>
<p>示例：</p>
<p>给定 “abcabcbb” ，没有重复字符的最长子串是 “abc” ，那么长度就是3。</p>
<p>给定 “bbbbb” ，最长的子串就是 “b” ，长度是1。</p>
<p>给定 “pwwkew” ，最长子串是 “wke” ，长度是3。请注意答案必须是一个子串，”pwke” 是 子序列  而不是子串。</p>
<p>这题有点意思，一开始就是自己想复杂了，用到了dp但是实际上根本不需要使用dp，其实就是一种找规律（窗体），和一定的优化方法（真的需要多一次遍历来进行去重吗），不要局限于之前的思想，要灵活</p>
<p>使用多一次循环去重<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Code03</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">lengthOfLongestSubstring</span><span class="params">(String s)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (s.length()==<span class="number">0</span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">char</span>[] at=s.toCharArray();</span><br><span class="line">        <span class="keyword">int</span> start = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> end =<span class="number">1</span>;</span><br><span class="line">        <span class="keyword">int</span> maxLength=<span class="number">1</span>;</span><br><span class="line">        <span class="keyword">int</span> nowLength=<span class="number">1</span>;</span><br><span class="line">        HashMap&lt;Character,Integer&gt; map = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">        map.put(at[<span class="number">0</span>],<span class="number">0</span>);</span><br><span class="line">        <span class="keyword">while</span>(end&lt;at.length)&#123;</span><br><span class="line">            Integer integer = map.get(at[end]);</span><br><span class="line">            <span class="keyword">if</span> (integer!=<span class="keyword">null</span>)&#123;</span><br><span class="line">                nowLength-=integer-start+<span class="number">1</span>;</span><br><span class="line">                start=integer+<span class="number">1</span>;</span><br><span class="line">                map.clear();</span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> a=start;a&lt;end;a++)&#123;</span><br><span class="line">                    map.put(at[a],a);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            map.put(at[end],end);</span><br><span class="line">            end++;</span><br><span class="line">            nowLength++;</span><br><span class="line">            maxLength = maxLength&gt;nowLength?maxLength:nowLength;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> maxLength;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>不使用循环去重<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>&#123;</span><br><span class="line">         <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">lengthOfLongestSubstring</span><span class="params">(String s)</span> </span>&#123;</span><br><span class="line">       <span class="keyword">int</span>[] map = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">256</span>];</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a=<span class="number">0</span>;a&lt;map.length;a++)&#123;</span><br><span class="line">            map[a]=-<span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">char</span>[] at = s.toCharArray();</span><br><span class="line">        <span class="keyword">int</span> start=<span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> length = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a=<span class="number">0</span>;a&lt;at.length;a++)&#123;</span><br><span class="line">            <span class="keyword">if</span> (map[at[a]]&gt;=start)&#123;</span><br><span class="line">                start= map[at[a]]+<span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">            &#125;</span><br><span class="line">            length= Math.max(length,a-start+<span class="number">1</span>);</span><br><span class="line">            map[at[a]]=a;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> length;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h3 id="两个排序数组的中位数"><a href="#两个排序数组的中位数" class="headerlink" title="两个排序数组的中位数"></a>两个排序数组的中位数</h3><p>我认为这道题是我做过的最有用的一道题目，我的思维有种漏洞，这道问题锻炼人的思维，两个排序的数组，找到第k个数字，其实很简单。两个假设<br>假设1第一个数组中有n个数字那么第二个数组中就只有k-n个数字了。<br>假设2第一个数组去i位置的数字，第二个数组取j位置的数字，那么可以得到一个结论i和j位置对应的最大的那个数字，绝对是位置&gt;=i+j的数字，然后在看看i和j的后一位，i小于j的后一位，j小于i的后一位，那么就i+j最小数都找到了。。。。。说的太操蛋了</p>
<p>说白了就是看到了 如果我知道前k个第一个数组有多少个那么我就知道了第二个数组数的个数一定是k-第一个数组个数的个数，并且有一个约束条件就是假设2，就实现了递归了</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">double</span> <span class="title">findMedianSortedArrays</span><span class="params">(<span class="keyword">int</span>[] nums1, <span class="keyword">int</span>[] nums2)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> all = nums1.length + nums2.length;</span><br><span class="line">        <span class="keyword">if</span> ((all) % <span class="number">2</span> == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> (finditme(nums1, nums2, all / <span class="number">2</span>) + finditme(nums1, nums2, all / <span class="number">2</span> + <span class="number">1</span>)) / <span class="number">2.0</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> (<span class="keyword">double</span>) finditme(nums1, nums2, all / <span class="number">2</span> + <span class="number">1</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">finditme</span><span class="params">(<span class="keyword">int</span>[] n1, <span class="keyword">int</span>[] n2, <span class="keyword">int</span> k)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (n1.length &gt; n2.length) &#123;</span><br><span class="line">            <span class="keyword">return</span> finditme(n2, n1, k);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">int</span> n1index = n1.length &lt; k ? n1.length : k;</span><br><span class="line">        <span class="keyword">int</span> n2index = k - n1index;</span><br><span class="line">        <span class="keyword">while</span> (<span class="keyword">true</span>) &#123;</span><br><span class="line">            <span class="keyword">int</span> n1l = n1index == <span class="number">0</span> ? Integer.MIN_VALUE : n1[n1index - <span class="number">1</span>];</span><br><span class="line">            <span class="keyword">int</span> n1r = n1index == n1.length ? Integer.MAX_VALUE : n1[n1index];</span><br><span class="line">            <span class="keyword">int</span> n2l = n2index == <span class="number">0</span> ? Integer.MIN_VALUE : n2[n2index - <span class="number">1</span>];</span><br><span class="line">            <span class="keyword">int</span> n2r = n2index == n2.length ? Integer.MAX_VALUE : n2[n2index];</span><br><span class="line">            <span class="keyword">if</span> (n1l &gt; n2r) &#123;</span><br><span class="line">                <span class="keyword">int</span> n = n2index/<span class="number">2</span>==<span class="number">0</span>?<span class="number">1</span>:n2index/<span class="number">2</span>;</span><br><span class="line">                <span class="keyword">int</span> end1 = n1index-n&lt;<span class="number">0</span>?n1index:n;</span><br><span class="line">                <span class="keyword">int</span> end2 = n2index+n&gt;n2.length?n2.length-n2index:n;</span><br><span class="line">                end1 = Math.min(end1,end2);</span><br><span class="line">                n1index-=end1;</span><br><span class="line">                n2index+=end1;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (n2l &gt; n1r) &#123;</span><br><span class="line">                <span class="keyword">int</span> n = n1index/<span class="number">2</span>==<span class="number">0</span>?<span class="number">1</span>:n1index/<span class="number">2</span>;</span><br><span class="line">                <span class="keyword">int</span> end1 = n2index-n&lt;<span class="number">0</span>?n2index:n;</span><br><span class="line">                <span class="keyword">int</span> end2 = n1index+n&gt;n1.length?n1.length-n1index:n;</span><br><span class="line">                end1 = Math.min(end1,end2);</span><br><span class="line">                n2index-=end1;</span><br><span class="line">                n1index+=end1;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="keyword">return</span> Math.max(n1l, n2l);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Code04</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="keyword">new</span> Code04().findMedianSortedArrays(</span><br><span class="line">                <span class="keyword">new</span> <span class="keyword">int</span>[]&#123;<span class="number">2</span>&#125;, <span class="keyword">new</span> <span class="keyword">int</span>[]&#123;<span class="number">1</span>, <span class="number">3</span>&#125;</span><br><span class="line">        ));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 我的做法很简单的 二分查找扩展，基于位置而不是值</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> nums1</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> nums2</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">double</span> <span class="title">findMedianSortedArrays</span><span class="params">(<span class="keyword">int</span>[] nums1, <span class="keyword">int</span>[] nums2)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (nums1.length == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> getzhong(nums2);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (nums2.length == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> getzhong(nums1);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (nums1.length == <span class="number">1</span> &amp;&amp; nums2.length == <span class="number">1</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> ((<span class="keyword">double</span>) nums1[<span class="number">0</span>] + (<span class="keyword">double</span>) nums2[<span class="number">0</span>]) / <span class="number">2.0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">int</span> index = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> end = <span class="number">2</span>;</span><br><span class="line">        <span class="keyword">int</span>[][] need = <span class="keyword">new</span> <span class="keyword">int</span>[][]&#123;</span><br><span class="line">                &#123;(nums1.length + nums2.length) / <span class="number">2</span> + <span class="number">1</span>, -<span class="number">1</span>&#125;,</span><br><span class="line">                &#123;(nums1.length + nums2.length) % <span class="number">2</span> == <span class="number">0</span> ?</span><br><span class="line">                        (nums1.length + nums2.length) / <span class="number">2</span> :</span><br><span class="line">                        (nums1.length + nums2.length) / <span class="number">2</span> + <span class="number">1</span>, -<span class="number">1</span>&#125;</span><br><span class="line">        &#125;;</span><br><span class="line">        <span class="keyword">while</span> (index &lt; end) &#123;</span><br><span class="line">            <span class="keyword">int</span> ns1 = <span class="number">0</span>, ne1 = nums1.length - <span class="number">1</span>;</span><br><span class="line">            <span class="keyword">int</span> ns2 = <span class="number">0</span>, ne2 = nums2.length - <span class="number">1</span>;</span><br><span class="line">            <span class="keyword">while</span> (<span class="keyword">true</span>) &#123;</span><br><span class="line">                <span class="keyword">int</span> needone = nums1[(ns1 + ne1) / <span class="number">2</span>];</span><br><span class="line">                <span class="keyword">int</span> needtwo = nums2[(ns2 + ne2) / <span class="number">2</span>];</span><br><span class="line">                <span class="keyword">int</span> indexone = getAllIndex(nums2, (ns1 + ne1) / <span class="number">2</span>, needone, ns2, ne2, <span class="number">1</span>);</span><br><span class="line">                <span class="keyword">int</span> indextwo = getAllIndex(nums1, (ns2 + ne2) / <span class="number">2</span>, needtwo, ns1, ne1, <span class="number">2</span>);</span><br><span class="line">                <span class="keyword">if</span> (indexone &gt; need[index][<span class="number">0</span>]) &#123;</span><br><span class="line">                    ne1 = ((ns1 + ne1) / <span class="number">2</span> - <span class="number">1</span>) &lt; ns1 ? ns1 : (ns1 + ne1) / <span class="number">2</span> - <span class="number">1</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (indexone &lt; need[index][<span class="number">0</span>]) &#123;</span><br><span class="line">                    ns1 = ((ns1 + ne1) / <span class="number">2</span> + <span class="number">1</span>) &gt; ne1 ? ne1 : (ns1 + ne1) / <span class="number">2</span> + <span class="number">1</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    need[index][<span class="number">1</span>] = needone;</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (indextwo &gt; need[index][<span class="number">0</span>]) &#123;</span><br><span class="line">                    ne2 = ((ns2 + ne2) / <span class="number">2</span> - <span class="number">1</span>) &lt; ns2 ? ns2 : (ns2 + ne2) / <span class="number">2</span> - <span class="number">1</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (indextwo &lt; need[index][<span class="number">0</span>]) &#123;</span><br><span class="line">                    ns2 = ((ns2 + ne2) / <span class="number">2</span> + <span class="number">1</span>) &gt; ne2 ? ne2 : (ns2 + ne2) / <span class="number">2</span> + <span class="number">1</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    need[index][<span class="number">1</span>] = needtwo;</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            index++;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> ((<span class="keyword">double</span>) need[<span class="number">0</span>][<span class="number">1</span>] + (<span class="keyword">double</span>) need[<span class="number">1</span>][<span class="number">1</span>]) / <span class="number">2</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">double</span> <span class="title">getzhong</span><span class="params">(<span class="keyword">int</span>[] nums1)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (nums1.length % <span class="number">2</span> == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> ((<span class="keyword">double</span>) nums1[(nums1.length / <span class="number">2</span> - <span class="number">1</span>)] + (<span class="keyword">double</span>) nums1[(nums1.length / <span class="number">2</span>)]) / <span class="number">2.0</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> nums1[nums1.length / <span class="number">2</span>];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getAllIndex</span><span class="params">(<span class="keyword">int</span>[] n, <span class="keyword">int</span> before, <span class="keyword">int</span> item, <span class="keyword">int</span> start, <span class="keyword">int</span> end, <span class="keyword">int</span> type)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">while</span> (start &lt; end) &#123;</span><br><span class="line">            <span class="keyword">if</span> (type == <span class="number">1</span>) &#123;</span><br><span class="line">                <span class="keyword">if</span> (item &gt; n[(start + end) / <span class="number">2</span>]) &#123;</span><br><span class="line">                    start = (start + end) / <span class="number">2</span> + <span class="number">1</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    end = (start + end) / <span class="number">2</span> - <span class="number">1</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                <span class="keyword">if</span> (item &gt;= n[(start + end) / <span class="number">2</span>]) &#123;</span><br><span class="line">                    start = (start + end) / <span class="number">2</span> + <span class="number">1</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    end = (start + end) / <span class="number">2</span> - <span class="number">1</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (n[start] &lt; item) &#123;</span><br><span class="line">            <span class="keyword">return</span> before + start + <span class="number">2</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> before + start + <span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="最长回文字串"><a href="#最长回文字串" class="headerlink" title="最长回文字串"></a>最长回文字串</h3><p>马拉车算法  —&gt; 一种思维，寻找关系，像回文数组 排序数组，都是有特性的，比如回文传回文中心左右是相同的，在排序数组中具有数据大小的特点，这题的思路就是典型的贪心，解决贪心问题的核心就是找到特点和发散思维</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Code05</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="keyword">new</span> Code05().longestPalindrome(<span class="string">"babad"</span>));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 使用Manacher算法</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> s</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">longestPalindrome</span><span class="params">(String s)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">char</span>[] at = <span class="keyword">new</span> <span class="keyword">char</span>[s.length() * <span class="number">2</span> + <span class="number">1</span>];</span><br><span class="line">        <span class="keyword">int</span>[] length = <span class="keyword">new</span> <span class="keyword">int</span>[s.length() * <span class="number">2</span> + <span class="number">1</span>];</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a = <span class="number">0</span>; a &lt; s.length(); a++) &#123;</span><br><span class="line">            at[a * <span class="number">2</span>] = <span class="string">'#'</span>;</span><br><span class="line">            at[<span class="number">2</span> * a + <span class="number">1</span>] = s.charAt(a);</span><br><span class="line">        &#125;</span><br><span class="line">        at[at.length - <span class="number">1</span>] = <span class="string">'#'</span>;</span><br><span class="line">        length[<span class="number">0</span>] = <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">int</span> nowIndex = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> index = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a = <span class="number">0</span>; a &lt; at.length; a++) &#123;</span><br><span class="line">            <span class="keyword">if</span> (nowIndex + length[nowIndex] &gt; a) &#123;</span><br><span class="line">                length[a] = Math.min(nowIndex + length[nowIndex] - a, length[<span class="number">2</span> * nowIndex - a]);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                length[a] = <span class="number">1</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">while</span> (a - length[a] &gt;= <span class="number">0</span> &amp;&amp; a + length[a] &lt;= at.length - <span class="number">1</span>) &#123;</span><br><span class="line">                <span class="keyword">if</span> (at[a - length[a]] == at[a + length[a]]) &#123;</span><br><span class="line">                    length[a]++;</span><br><span class="line">                    <span class="keyword">continue</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//break;</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (a + length[a] &gt; nowIndex + length[nowIndex]) &#123;</span><br><span class="line">                nowIndex = a;</span><br><span class="line">            &#125;</span><br><span class="line">            index = length[index] &lt; length[a] ? a : index;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> getString(index,length,at);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getString</span><span class="params">(<span class="keyword">int</span> index, <span class="keyword">int</span>[] length, <span class="keyword">char</span>[] at)</span> </span>&#123;</span><br><span class="line">        ArrayList&lt;Character&gt; arrayList = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> start = index - length[index] + <span class="number">1</span>, end = index + length[index] - <span class="number">1</span>; start &lt;= end; start++) &#123;</span><br><span class="line">            <span class="keyword">if</span> (at[start] != <span class="string">'#'</span>) &#123;</span><br><span class="line">                arrayList.add(at[start]);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">char</span>[] c = <span class="keyword">new</span> <span class="keyword">char</span>[arrayList.size()];</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a=<span class="number">0</span>;a&lt;arrayList.size();a++)&#123;</span><br><span class="line">            c[a]=arrayList.get(a);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> String(c);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="Z-字形变换"><a href="#Z-字形变换" class="headerlink" title="Z 字形变换"></a>Z 字形变换</h3><p>将字符串 “PAYPALISHIRING” 以Z字形排列成给定的行数：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">P   A   H   N</span><br><span class="line">A P L S I I G</span><br><span class="line">Y   I   R</span><br></pre></td></tr></table></figure></p>
<p>之后从左往右，逐行读取字符：”PAHNAPLSIIGYIR”</p>
<p>这个提我的思路就将这个问题分解 Z 字形从上倒下是一类，斜着是一类分类解决</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Code06</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="keyword">new</span> Code06().convert(<span class="string">"A"</span>,<span class="number">1</span>));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">convert</span><span class="params">(String s, <span class="keyword">int</span> numRows)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(s.equals(<span class="string">""</span>)||numRows==<span class="number">1</span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> s;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">char</span>[] ca= <span class="keyword">new</span> <span class="keyword">char</span>[s.length()];</span><br><span class="line">        <span class="keyword">char</span>[] item = s.toCharArray();</span><br><span class="line">        <span class="keyword">int</span> speed = numRows*<span class="number">2</span>-<span class="number">2</span>;</span><br><span class="line">        <span class="keyword">int</span> speed2 = speed;</span><br><span class="line">        <span class="keyword">int</span> index=<span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> line = s.length()%speed==<span class="number">0</span>?s.length()/speed:s.length()/speed+<span class="number">1</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a=<span class="number">0</span>;a&lt;numRows;a++)&#123;</span><br><span class="line">            speed2=speed-<span class="number">2</span>*a;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> b=<span class="number">0</span>;b&lt;line;b++)&#123;</span><br><span class="line">                <span class="keyword">if</span> (b*speed+a&lt;s.length())&#123;</span><br><span class="line">                    ca[index]=item[b*speed+a];</span><br><span class="line">                    index++;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (speed2!=<span class="number">0</span>&amp;&amp;(b*speed+a+speed2)%speed!=<span class="number">0</span>&amp;&amp;b*speed+a+speed2&lt;s.length())&#123;</span><br><span class="line">                    ca[index]=item[b*speed+a+speed2];</span><br><span class="line">                    index++;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> String(ca);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="反转整数"><a href="#反转整数" class="headerlink" title="反转整数"></a>反转整数</h3><p>这个没什么就是有一种思路使用long 类型解决int 类型溢出的问题，还可以使用使用异常的方法解决这个问题</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Code7</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="keyword">new</span> Code7().reverse(-<span class="number">2147483412</span>));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">reverse</span><span class="params">(<span class="keyword">int</span> x)</span> </span>&#123;</span><br><span class="line">        String s = String.valueOf(x);</span><br><span class="line">        <span class="keyword">if</span> (x&gt;=<span class="number">0</span>)&#123;</span><br><span class="line">            s=<span class="string">"+"</span>+s;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">char</span> c[] = s.toCharArray();</span><br><span class="line">        <span class="keyword">char</span> c2[] = <span class="keyword">new</span> <span class="keyword">char</span>[c.length];</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a=<span class="number">1</span>;a&lt;c.length;a++)&#123;</span><br><span class="line">            c2[c.length-a]=c[a];</span><br><span class="line">        &#125;</span><br><span class="line">        c2[<span class="number">0</span>]=c[<span class="number">0</span>];</span><br><span class="line">        <span class="keyword">if</span> (c2.length-<span class="number">1</span>&gt;=<span class="number">10</span>)&#123;<span class="comment">// 不必考虑2的31次方-1的情况应为肯定取不到</span></span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> a=<span class="number">1</span>,b=<span class="number">0</span>;a&lt;c2.length;a++,b++)&#123;</span><br><span class="line">                <span class="keyword">if</span>(b&gt;=<span class="number">10</span>||c2[a]&gt;MAXVULE[b])&#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">                &#125;<span class="keyword">else</span> <span class="keyword">if</span> (c2[a]&lt;MAXVULE[b])&#123;</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                    <span class="keyword">continue</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> Integer.valueOf(<span class="keyword">new</span> String(c2));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">char</span>[] MAXVULE = <span class="keyword">new</span> <span class="keyword">char</span>[]&#123;<span class="string">'2'</span>,<span class="string">'1'</span>,<span class="string">'4'</span>,<span class="string">'7'</span>,<span class="string">'4'</span>,<span class="string">'8'</span>,<span class="string">'3'</span>,<span class="string">'6'</span>,<span class="string">'4'</span>,<span class="string">'8'</span>&#125;;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">reverse2</span><span class="params">(<span class="keyword">int</span> x)</span> </span>&#123;</span><br><span class="line">        String s = String.valueOf(x);</span><br><span class="line">        <span class="keyword">if</span> (x&gt;=<span class="number">0</span>)&#123;</span><br><span class="line">            s=<span class="string">"+"</span>+s;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">char</span> c[] = s.toCharArray();</span><br><span class="line">        <span class="keyword">char</span> c2[] = <span class="keyword">new</span> <span class="keyword">char</span>[c.length];</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a=<span class="number">1</span>;a&lt;c.length;a++)&#123;</span><br><span class="line">            c2[c.length-a]=c[a];</span><br><span class="line">        &#125;</span><br><span class="line">        c2[<span class="number">0</span>]=c[<span class="number">0</span>];</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> Integer.valueOf(<span class="keyword">new</span> String(c2));</span><br><span class="line">        &#125;<span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">reverse3</span><span class="params">(<span class="keyword">int</span> x)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">boolean</span> negative = x &lt; <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">if</span> (negative) x = -x;</span><br><span class="line">        <span class="keyword">long</span> r = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">while</span> (x&gt;<span class="number">0</span>) &#123;</span><br><span class="line">            r = r * <span class="number">10</span> + x % <span class="number">10</span>;</span><br><span class="line">            x /= <span class="number">10</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (negative) r = -r;</span><br><span class="line">        <span class="keyword">if</span> (r &gt; Integer.MAX_VALUE || r &lt; Integer.MIN_VALUE) <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">return</span> (<span class="keyword">int</span>)r;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="回文数"><a href="#回文数" class="headerlink" title="回文数"></a>回文数</h3><p>判断一个整数是否是回文数。回文数是指正序（从左向右）和倒序（从右向左）读都是一样的整数。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">输入: 121</span><br><span class="line">输出: true</span><br><span class="line">示例 2:</span><br></pre></td></tr></table></figure>
<p>最好的思路，回文数的特点就是正的和反的是相同的也就是说将这个从后到前变成整数就可以判断了</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Code9</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="keyword">new</span> Code9().isPalindrome(<span class="number">1000000001</span>));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">isPalindrome</span><span class="params">(<span class="keyword">int</span> x)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (x&lt;<span class="number">0</span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">long</span> maxPath = getItemPath(x);</span><br><span class="line">        <span class="keyword">long</span> minPath = <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">while</span> (minPath &lt;= maxPath) &#123;</span><br><span class="line">            <span class="keyword">int</span> before = (<span class="keyword">int</span>) (x / (maxPath / <span class="number">10</span>)-(x/maxPath)*<span class="number">10</span>);</span><br><span class="line">            <span class="keyword">int</span> end = (<span class="keyword">int</span>) ((x % (minPath * <span class="number">10</span>) - x % minPath)/minPath);</span><br><span class="line">            <span class="keyword">if</span> (before != end) &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                maxPath /= <span class="number">10</span>;</span><br><span class="line">                minPath *= <span class="number">10</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">getItemPath</span><span class="params">(<span class="keyword">int</span> x)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">long</span> a = <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">do</span> &#123;</span><br><span class="line">            x = x / <span class="number">10</span>;</span><br><span class="line">            a *= <span class="number">10</span>;</span><br><span class="line">        &#125; <span class="keyword">while</span> (x &gt; <span class="number">0</span>);</span><br><span class="line">        <span class="keyword">return</span> a;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 第二种解法</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> input</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">isPalindrome2</span><span class="params">(<span class="keyword">int</span> input)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (input &lt; <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">boolean</span> result = <span class="keyword">false</span>;</span><br><span class="line">        <span class="keyword">int</span> origin = input;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">int</span> temp = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">while</span> (input != <span class="number">0</span>) &#123;</span><br><span class="line">            temp = temp * <span class="number">10</span> + input % <span class="number">10</span>;</span><br><span class="line">            input = input / <span class="number">10</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (temp == origin) &#123;</span><br><span class="line">            result = <span class="keyword">true</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span>  result;     </span><br><span class="line">        </span><br><span class="line">    &#125;   </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/详解http协议-状态码和报文信息/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/详解http协议-状态码和报文信息/" itemprop="url">未命名</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:22:37+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="http状态碼"><a href="#http状态碼" class="headerlink" title="http状态碼"></a>http状态碼</h3><blockquote>
<p>2xx表示成功</p>
</blockquote>
<ul>
<li>200：OK 表示服务器正常处理</li>
<li>206：表示客户端进行了范围请求，服务返回行了范围请求</li>
</ul>
<blockquote>
<p>3xx重定向</p>
</blockquote>
<ul>
<li>301：永久重定向，表示uri已经分配了新的地址，以后使用这个uri访问资源</li>
<li>302：临时重定向，表示只是暂时的分配了新的地址，本次请求使用新的地址</li>
<li>303：临时重定向，和302区别时要求客户端使用get方法进行请求</li>
<li>304:为满足条件，表示服务器可以进行请求，但是没有满足head中的（if-×）类型字段的条件</li>
</ul>
<blockquote>
<p>4xx表示客户端错误</p>
</blockquote>
<ul>
<li>400：语法错误</li>
<li>401：需要进行验证</li>
<li>403：访问被拒绝</li>
<li>404：服务器上无法找到被请求的资源</li>
</ul>
<blockquote>
<p>5xx服务器错误</p>
</blockquote>
<ul>
<li>500：服务器故障</li>
<li>503：服务器超负荷，或停机维护，服务器返回Retry-after表示需要的时间</li>
</ul>
<h3 id="http协议首部字段的书写格式"><a href="#http协议首部字段的书写格式" class="headerlink" title="http协议首部字段的书写格式"></a>http协议首部字段的书写格式</h3><p><img src="/blogimg/http2/1.png" alt=""></p>
<h3 id="http协议通用首部字段"><a href="#http协议通用首部字段" class="headerlink" title="http协议通用首部字段"></a>http协议通用首部字段</h3><p><img src="/blogimg/http2/2.png" alt=""></p>
<h4 id="cache-Control"><a href="#cache-Control" class="headerlink" title="cache-Control"></a>cache-Control</h4><p><strong>格式</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Cache-Control: <span class="keyword">private</span>,max-age=<span class="number">0</span>,no-cache</span><br></pre></td></tr></table></figure>
<p><strong>作用：</strong>操作缓存机制</p>
<blockquote>
<p>缓存请求指令</p>
</blockquote>
<p><img src="/blogimg/http2/3.png" alt=""></p>
<p><img src="/blogimg/http2/4.png" alt=""></p>
<blockquote>
<p>缓存响应指令</p>
</blockquote>
<p><img src="/blogimg/http2/5.png" alt=""></p>
<h4 id="connection"><a href="#connection" class="headerlink" title="connection"></a>connection</h4><p>控制代理表明相关的字段不被转发 和管理持久链接</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Connection:不被转发的字段名称</span><br></pre></td></tr></table></figure>
<blockquote>
<p>关闭持久链接</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">connection:close</span><br></pre></td></tr></table></figure>
<blockquote>
<p>开启持久链接</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">connection:keep-alive</span><br></pre></td></tr></table></figure>
<h4 id="data"><a href="#data" class="headerlink" title="data"></a>data</h4><blockquote>
<p>创建时间的报文</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Date:Sun, <span class="number">08</span> Oct <span class="number">2017</span> <span class="number">11</span>:<span class="number">30</span>:<span class="number">41</span> GMT</span><br></pre></td></tr></table></figure>
<blockquote>
<p>Trailer</p>
</blockquote>
<p>首部字段Trailer会事先说明报文主体后记录了那些首部字段。该首部字段可应用在HTTP/1.1版本分块传输编码时。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Transfer-Encoding:chunk</span><br><span class="line">Trailer:Expires</span><br><span class="line"> </span><br><span class="line">cf0   &lt;---<span class="number">16</span>进制 <span class="number">10</span>进制<span class="number">3312</span></span><br><span class="line">-----<span class="number">3312</span>-字节-----</span><br><span class="line"><span class="number">0</span> &lt;----表示结束</span><br><span class="line">Expires：Thu，<span class="number">15</span> Apr  <span class="number">2010</span>  <span class="number">20</span>：<span class="number">00</span>：<span class="number">00</span>  GMT;</span><br></pre></td></tr></table></figure>
<h4 id="Transfer-Encoding-chunk"><a href="#Transfer-Encoding-chunk" class="headerlink" title="Transfer-Encoding:chunk"></a>Transfer-Encoding:chunk</h4><blockquote>
<p>http1.1中表示分块请求</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Transfer-Encoding:chunk</span><br><span class="line">Trailer:Expires</span><br><span class="line">cf0   &lt;---<span class="number">16</span>进制 <span class="number">10</span>进制<span class="number">3312</span></span><br><span class="line">-----<span class="number">3312</span>-字节-----</span><br><span class="line"><span class="number">392</span></span><br><span class="line">----<span class="number">914</span>字节-----</span><br><span class="line"><span class="number">0</span> &lt;----表示结束</span><br><span class="line">Expires：Thu，<span class="number">15</span> Apr  <span class="number">2010</span>  <span class="number">20</span>：<span class="number">00</span>：<span class="number">00</span>  GMT;</span><br></pre></td></tr></table></figure>
<h4 id="upgrade"><a href="#upgrade" class="headerlink" title="upgrade"></a>upgrade</h4><p>表明是否支持更加高级的协议</p>
<p><img src="/blogimg/http2/6.png" alt=""></p>
<h4 id="via"><a href="#via" class="headerlink" title="via"></a>via</h4><blockquote>
<p>一般和trace连用用来追踪服务器信息</p>
</blockquote>
<p><img src="/blogimg/http2/7.png" alt=""></p>
<h3 id="http协议请求首部字段"><a href="#http协议请求首部字段" class="headerlink" title="http协议请求首部字段"></a>http协议请求首部字段</h3><p><img src="/blogimg/http2/8.png" alt=""></p>
<h4 id="Accept等"><a href="#Accept等" class="headerlink" title="Accept等"></a>Accept等</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Accept:image/webp,image/apng,image<span class="comment">/*,*/</span>*;q=<span class="number">0.8</span></span><br><span class="line">Accept-Encoding:gzip, deflate, br</span><br><span class="line">Accept-Language:zh-CN,zh;q=<span class="number">0.8</span></span><br><span class="line">Accept-Charset:UTF-<span class="number">8</span>;q=<span class="number">0.8</span>,iso-<span class="number">8859</span>-<span class="number">5</span></span><br></pre></td></tr></table></figure>
<h4 id="authorization和proxy-authrization"><a href="#authorization和proxy-authrization" class="headerlink" title="authorization和proxy-authrization"></a>authorization和proxy-authrization</h4><p>认证相关：401等</p>
<h4 id="form"><a href="#form" class="headerlink" title="form"></a>form</h4><p>使用代理的时候告诉电子邮箱的地址</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">form: <span class="number">1409915687</span><span class="meta">@qq</span>.com</span><br></pre></td></tr></table></figure>
<h4 id="if-xxx"><a href="#if-xxx" class="headerlink" title="if-xxx"></a>if-xxx</h4><p>if-match：比对match参数和文件的ETag值 相同返回200 否则412</p>
<p><img src="/blogimg/http2/9.png" alt=""></p>
<p>if-Modified-Since:表示返回文件的最后更新底线，如果文件的实际更新时间在字段时间之前则失败反之成功  （if-unmodifed-since 和这个作用相反）<br><img src="/blogimg/http2/10.png" alt=""><br>if-no-match:和if-mathch 作用相反，不匹配的时候返回成功<br><img src="/blogimg/http2/11.png" alt=""><br>if-Range：如果该字段的ETag值或者时间相同就允许做范围资源请求<br><img src="/blogimg/http2/12.png" alt=""></p>
<h4 id="Max-forwards"><a href="#Max-forwards" class="headerlink" title="Max-forwards"></a>Max-forwards</h4><p>指定转发的次数</p>
<p><img src="/blogimg/http2/13.png" alt=""></p>
<h4 id="Range"><a href="#Range" class="headerlink" title="Range"></a>Range</h4><p>范围返回</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Range：bytes：<span class="number">100</span>-<span class="number">2000</span></span><br></pre></td></tr></table></figure>
<h4 id="TE"><a href="#TE" class="headerlink" title="TE"></a>TE</h4><p>指定传输编码的方式– 可以使用trailers指定的相关字段</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">TE:trailers</span><br></pre></td></tr></table></figure>
<h4 id="User-Agent"><a href="#User-Agent" class="headerlink" title="User-Agent"></a>User-Agent</h4><p>用户的浏览器相关的信息</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">User-Agent:Mozilla/<span class="number">5.0</span> (X11; Linux x86_64) AppleWebKit/<span class="number">537.36</span> (KHTML, like Gecko) Chrome/<span class="number">61.0</span>.3163.100 Safari/<span class="number">537.36</span></span><br></pre></td></tr></table></figure>
<h3 id="http协议响应首部字段"><a href="#http协议响应首部字段" class="headerlink" title="http协议响应首部字段"></a>http协议响应首部字段</h3><p><img src="/blogimg/http2/14.png" alt=""></p>
<p><img src="/blogimg/http2/15.png" alt=""></p>
<h4 id="ETag"><a href="#ETag" class="headerlink" title="ETag"></a>ETag</h4><p>资源的唯一标识符，当使用不同的语言环境的时候可能会出现相同的uri地址但是指向的却是不同的资源，这就使用ETag进一步标识所要使用的资源</p>
<p><img src="/blogimg/http2/16.png" alt=""></p>
<h4 id="location"><a href="#location" class="headerlink" title="location"></a>location</h4><p>配合3xx 表示重定向的地址</p>
<h4 id="Retry-after"><a href="#Retry-after" class="headerlink" title="Retry-after"></a>Retry-after</h4><p>指定多久呵在进行相应，配合503</p>
<h4 id="server"><a href="#server" class="headerlink" title="server"></a>server</h4><p>表示服务器信息</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">server：nginx/<span class="number">1.12</span>.0</span><br></pre></td></tr></table></figure>
<h4 id="Vary"><a href="#Vary" class="headerlink" title="Vary"></a>Vary</h4><p><img src="/blogimg/http2/17.png" alt=""></p>
<h3 id="http协议实体首部字段"><a href="#http协议实体首部字段" class="headerlink" title="http协议实体首部字段"></a>http协议实体首部字段</h3><p><img src="/blogimg/http2/18.png" alt=""></p>
<h4 id="allow"><a href="#allow" class="headerlink" title="allow"></a>allow</h4><p>指定服务器指定的uri请求方法GET等</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Allow：GET,POST</span><br></pre></td></tr></table></figure>
<h4 id="Content"><a href="#Content" class="headerlink" title="Content-*"></a>Content-*</h4><p>实体部分的编码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Content-Encode：gzip</span><br><span class="line">Content-Language：zh-CN</span><br><span class="line">Content-Length:<span class="number">15000</span></span><br><span class="line">Content-Location:www.hi-kys.me</span><br><span class="line">Content-MD5:UEUEJDJNWIQSNNFIFNEF=</span><br><span class="line">Content-Range:bytes:<span class="number">500</span>-<span class="number">1000</span>/<span class="number">1000</span></span><br><span class="line">Content-Type:text/html;charset=UTF-<span class="number">8</span></span><br></pre></td></tr></table></figure>
<h4 id="Expires"><a href="#Expires" class="headerlink" title="Expires"></a>Expires</h4><p>指定资源失效的日期，优先级小于Cache-Control：max-age</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Expires：Thu，<span class="number">15</span> Apr <span class="number">2010</span> <span class="number">20</span>：<span class="number">00</span>：<span class="number">00</span> GMT;</span><br></pre></td></tr></table></figure>
<h4 id="last-Modified"><a href="#last-Modified" class="headerlink" title="last-Modified"></a>last-Modified</h4><p>返回文件最终修改日期</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Last-Modified：Thu，<span class="number">15</span> Apr  <span class="number">2010</span>  <span class="number">20</span>：<span class="number">00</span>：<span class="number">00</span>  GMT</span><br></pre></td></tr></table></figure>
<h3 id="其他非http-1-1首部"><a href="#其他非http-1-1首部" class="headerlink" title="其他非http/1.1首部"></a>其他非http/1.1首部</h3><h4 id="cookie和setcookie"><a href="#cookie和setcookie" class="headerlink" title="cookie和setcookie"></a>cookie和setcookie</h4><p>cookie相应格式</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Set-Cookie:sid=<span class="number">123</span>[;name=value....];status=enable;expires=Thu <span class="string">' 15 Apr 2019 20:00:00  GMT;path=/;domain=.hackr.com</span></span><br></pre></td></tr></table></figure>
<p>相关字段属性</p>
<p><img src="/blogimg/http2/19.png" alt=""></p>
<p><img src="/blogimg/http2/20.png" alt=""></p>
<ul>
<li>Domain：域，表示当前cookie所属于哪个域或子域下面。</li>
<li>Path：表示cookie的所属路径。</li>
<li>Expire time/Max-age：表示了cookie的有效期。expire的值，是一个时间，过了这个时间，该cookie就失效了。或者是用max-age指定当前cookie是在多长时间之后而失效。如果服务器返回的一个cookie，没有指定其expire time，那么表明此cookie有效期只是当前的session，即是session cookie，当前session会话结束后，就过期了。对应的，当关闭（浏览器中）该页面的时候，此cookie就应该被浏览器所删除了。</li>
<li>secure：表示该cookie只能用https传输。一般用于包含认证信息的cookie，要求传输此cookie的时候，必须用https传输。</li>
<li>httponly：表示此cookie必须用于http或https传输。这意味着，浏览器脚本，比如javascript中，是不允许访问操作此cookie的。</li>
</ul>
<p>从客户端发送cookie给服务器的时候，是不发送cookie的各个属性的，而只是发送对应的名称和值。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Cookie：sid=<span class="number">123</span>[;name=value....]</span><br></pre></td></tr></table></figure>
<h3 id="http首部基于缓存代理和非缓存代理行为的分类"><a href="#http首部基于缓存代理和非缓存代理行为的分类" class="headerlink" title="http首部基于缓存代理和非缓存代理行为的分类"></a>http首部基于缓存代理和非缓存代理行为的分类</h3><ol>
<li>端到端首部 : 转换过程中不能丢失，必须转发的首部</li>
<li>逐跳首部 : http1.1需要提供connection字段，经过一层代理之后可以不进行转发</li>
</ol>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/深入理解mybatis（二）映射文件/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/深入理解mybatis（二）映射文件/" itemprop="url">未命名</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:22:37+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="深入理解mybatis（二）映射文件"><a href="#深入理解mybatis（二）映射文件" class="headerlink" title="深入理解mybatis（二）映射文件"></a>深入理解mybatis（二）映射文件</h2><p>MyBatis 的真正强大在于它的映射语句，也是它的魔力所在。由于它的异常强大，映射器的 XML 文件就显得相对简单。如果拿它跟具有相同功能的 JDBC 代码进行对比，你会立即发现省掉了将近 95% 的代码。MyBatis 就是针对 SQL 构建的，并且比普通的方法做的更好。</p>
<h3 id="配置文件总览"><a href="#配置文件总览" class="headerlink" title="配置文件总览"></a>配置文件总览</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span><br><span class="line"><span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- mybatis中使用自动映射的文件的时候需要使用一个接口所以 --&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- mapper标签中的namespace 表示配置文件的接口 --&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- !!!!这里非常重要 注意下面语句标签的时候必须加上命名空间才是最好的这样可以防止调用重复 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"S_Mybatis.c_Mapping接口.Mymapping接口"</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--映射器 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"getJavaBean"</span>  <span class="attr">parameterType</span>=<span class="string">"int"</span> <span class="attr">resultType</span>=<span class="string">"S_Mybatis.z_javabean.MyjavaBean"</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 1. select 标签 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">                    -标签属性-</span></span><br><span class="line"><span class="comment">            1.id   				表示使用接口中那个方法对应这个标签,命名标准使用方法名称</span></span><br><span class="line"><span class="comment">            2.parameterType		表示传入进这个标签所使用的数据的封转集合,</span></span><br><span class="line"><span class="comment">                                (可以使用int等基本类型,如果有多个类型,需要使用java对象进行封装)</span></span><br><span class="line"><span class="comment">                                取参数使用ognl表示方法 #&#123;xx.xxx&#125;</span></span><br><span class="line"><span class="comment">            3.returntype		表示方法返回值对应的类型可以使用基本类型或者使用自定义的</span></span><br><span class="line"><span class="comment">                                javabean-(必须使在允许自动匹配的条件下)</span></span><br><span class="line"><span class="comment">            4.returnMap			使用映射集引用来作为返回值值的匹配项相当于returntype的复杂形式(不允许在自动配置的条件下)</span></span><br><span class="line"><span class="comment">            5.flushCache		将其设置为 true，任何时候只要语句被调用，都会导致本地缓存和二级缓存都会被清空，默认值：false。</span></span><br><span class="line"><span class="comment">             6.useCache			将其设置为 true，将会导致本条语句的结果被二级缓存，默认值：对 select 元素为 true。</span></span><br><span class="line"><span class="comment">             7.timeout			这个设置是在抛出异常之前，驱动程序等待数据库返回请求结果的秒数。默认值为 unset（依赖驱动）。</span></span><br><span class="line"><span class="comment">             8.resultOrdered		这个设置仅针对嵌套结果 select 语句适用：如果为 true，就是假设包含了嵌套结果集或是分组了，</span></span><br><span class="line"><span class="comment">                                 这样的话当返回一个主结果行的时候，就不会发生有对前面结果集的引用的情况。</span></span><br><span class="line"><span class="comment">                                 这就使得在获取嵌套的结果集的时候,不至于导致内存不够用。默认值：false。</span></span><br><span class="line"><span class="comment">            9.resultSets		这个设置仅对多结果集的情况适用，它将列出语句执行后返回的结果集并每个结果集给一个名称，名称是逗号分隔的。</span></span><br><span class="line"><span class="comment">             10.statementType	告诉mybatis使用JDBC那个statement工作-STATEMENT，PREPARED 或 CALLABLE 的一个</span></span><br><span class="line"><span class="comment">                                 (statement,prepared,CallableStatement)</span></span><br><span class="line"><span class="comment">             11.resultSet		对应resultSet接口FORWARD_ONLY(允许有向前访问)，SCROLL_SENSITIVE</span></span><br><span class="line"><span class="comment">                                 (双向跟踪但是修改不会及时反映出来) 或 SCROLL_INSENSITIVE(双向修改结果及时反映出来)</span></span><br><span class="line"><span class="comment">                                 中的一个，默认值为 unset （依赖驱动）。</span></span><br><span class="line"><span class="comment">             12.databaseID		匹配数据库是指的数据库标识(在xml配置文件中使用的databaseIdPr) </span></span><br><span class="line"><span class="comment">             13.</span></span><br><span class="line"><span class="comment">        --&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">"insertJavabean"</span> &gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">            2.insert update delete标签相关属性</span></span><br><span class="line"><span class="comment">            id					命名空间中的唯一标识符，可被用来代表这条语句。</span></span><br><span class="line"><span class="comment">            parameterType		将要传入语句的参数的完全限定类名或别名。这个属性是可选的，因为 MyBatis 可以通过 TypeHandler</span></span><br><span class="line"><span class="comment">                                推断出具体传入语句的参数，默认值为 unset。</span></span><br><span class="line"><span class="comment">            parameterMap		这是引用外部 parameterMap 的已经被废弃的方法。使用内联参数映射和 parameterType 属性。</span></span><br><span class="line"><span class="comment">            flushCache			将其设置为 true，任何时候只要语句被调用，都会导致本地缓存和二级缓存都会被清空，</span></span><br><span class="line"><span class="comment">                                默认值：true（对应插入、更新和删除语句）。</span></span><br><span class="line"><span class="comment">            timeout				这个设置是在抛出异常之前，驱动程序等待数据库返回请求结果的秒数。默认值为 unset（依赖驱动）。</span></span><br><span class="line"><span class="comment">            statementType		STATEMENT，PREPARED 或 CALLABLE 的一个。这会让 MyBatis 分别使用 Statement，</span></span><br><span class="line"><span class="comment">                                PreparedStatement 或 CallableStatement，默认值：PREPARED。</span></span><br><span class="line"><span class="comment">            useGeneratedKeys	(仅对 insert 和 update 有用）这会令 MyBatis 使用 JDBC 的 getGeneratedKeys</span></span><br><span class="line"><span class="comment">                                方法来取出由数据库内部生成的主键-就是主键自动增加</span></span><br><span class="line"><span class="comment">            keyProperty			(仅对 insert 和 update 有用）这个属性是列名称表示当使用数据库自增的属性的时候</span></span><br><span class="line"><span class="comment">                                这个属性表示传入的参数对象</span></span><br><span class="line"><span class="comment">            keyColumn			(仅对 insert 和 update 有用）这个属性是数字表示第几列这个属性和上面的效果相同 - </span></span><br><span class="line"><span class="comment">            databaseId			如果配置了 databaseIdProvider，MyBatis 会加载所有的不带 databaseId 或匹配当前 databaseId</span></span><br><span class="line"><span class="comment">                                的语句；如果带或者不带的语句都有，则不带的会被忽略。		</span></span><br><span class="line"><span class="comment">        --&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">update</span> <span class="attr">id</span>=<span class="string">"updateJavabean"</span>&gt;</span><span class="tag">&lt;/<span class="name">update</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">delete</span> <span class="attr">id</span>=<span class="string">"deleteJavabean"</span>&gt;</span><span class="tag">&lt;/<span class="name">delete</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">"x"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">selectKey</span>&gt;</span><span class="tag">&lt;/<span class="name">selectKey</span>&gt;</span><span class="comment">&lt;!-- 这个标签可以用来对属性属性进行定制但是不要使用因为很麻烦 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 3.sql标签-动态的声明了一个可以进行任意嵌入的代码片段 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">sql</span> <span class="attr">id</span>=<span class="string">"userColumns"</span>&gt;</span> $&#123;alias&#125;.id,$&#123;alias&#125;.username,$&#123;alias&#125;.password <span class="tag">&lt;/<span class="name">sql</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 4.include-引入一个sql标签 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">""</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">include</span> <span class="attr">refid</span>=<span class="string">"userColumns"</span>&gt;</span><span class="tag">&lt;/<span class="name">include</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 5.cache mybatis默认只是开启了一级缓存也就是说针对于同一个sqlsession才会缓存 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">cache</span>&gt;</span><span class="tag">&lt;/<span class="name">cache</span>&gt;</span><span class="comment">&lt;!-- 简单的只使用这一个标签就是开启了二级缓存,默认的配置是 --&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">        默认属性：-!!!默认属性可以被select标签的usecache属性显示的表示是否使用缓存</span></span><br><span class="line"><span class="comment">        映射语句文件中的所有 select 语句将会被缓存。</span></span><br><span class="line"><span class="comment">        映射语句文件中的所有 insert,update 和 delete 语句会刷新缓存。</span></span><br><span class="line"><span class="comment">        缓存会使用 Least Recently Used(LRU,最近最少使用的)算法来收回。</span></span><br><span class="line"><span class="comment">        根据时间表(比如 no Flush Interval,没有刷新间隔), 缓存不会以任何时间顺序 来刷新。</span></span><br><span class="line"><span class="comment">        缓存会存储列表集合或对象(无论查询方法返回什么)的 1024 个引用。</span></span><br><span class="line"><span class="comment">        缓存会被视为是 read/write(可读/可写)的缓存,意味着对象检索不是共享的,</span></span><br><span class="line"><span class="comment">        而且可以安全地被调用者修改,而不干扰其他调用者或线程所做的潜在修改。</span></span><br><span class="line"><span class="comment">        flushInterval(刷新间隔)可以被设置为任意的正整数,而且它们代表一个合理的毫秒形式的时间段。</span></span><br><span class="line"><span class="comment">        默认情况是不设置,也就是没有刷新间隔,</span></span><br><span class="line"><span class="comment">        缓存仅仅调用语句时刷新</span></span><br><span class="line"><span class="comment">     --&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 使用默认的缓存的时候可以进行相应的配置 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">cache</span> <span class="attr">eviction</span>=<span class="string">"FIFO"</span> <span class="attr">flushInterval</span>=<span class="string">"60000"</span> <span class="attr">size</span>=<span class="string">"512"</span> <span class="attr">readOnly</span>=<span class="string">"true"</span>/&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 开启缓存</span></span><br><span class="line"><span class="comment">        size(引用数目)	可以被设置为任意正整数,要记住你缓存的对象数目和你运行环境的 可用内存资源数目。默认值是 1024。</span></span><br><span class="line"><span class="comment">        readOnly(只读)	属性可以被设置为 true 或 false。只读的缓存会给所有调用者返回缓 存对象的相同实例。</span></span><br><span class="line"><span class="comment">                        因此这些对象不能被修改。这提供了很重要的性能优势。</span></span><br><span class="line"><span class="comment">                        可读写的缓存 会返回缓存对象的拷贝(通过序列化) 。</span></span><br><span class="line"><span class="comment">                        这会慢一些,但是安全,因此默认是 false。</span></span><br><span class="line"><span class="comment">        eviction 缓存策略：</span></span><br><span class="line"><span class="comment">                        LRU – 最近最少使用的:移除最长时间不被使用的对象。</span></span><br><span class="line"><span class="comment">                        FIFO – 先进先出:按对象进入缓存的顺序来移除它们。</span></span><br><span class="line"><span class="comment">                        SOFT – 软引用:移除基于垃圾回收器状态和软引用规则的对象。</span></span><br><span class="line"><span class="comment">                        WEAK – 弱引用:更积极地移除基于垃圾收集器状态和弱引用规则的对象。</span></span><br><span class="line"><span class="comment">     --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">cache</span> <span class="attr">type</span>=<span class="string">"S_Mybatis.e_自定义mybatis缓存.自定义缓存文件"</span>&gt;</span><span class="tag">&lt;/<span class="name">cache</span>&gt;</span><span class="comment">&lt;!-- 自定义缓存 --&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- &lt;cache-ref namespace="com.someone.application.data.SomeMapper"/&gt; --&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--参照缓存： 回想一下上一节内容, 这个特殊命名空间的唯一缓存会被使用或者刷新相同命名空间内的语句。</span></span><br><span class="line"><span class="comment">                也许将来的某个时候,你会想在命名空间中共享</span></span><br><span class="line"><span class="comment">                相同的缓存配置和实例。在这样的 情况下你可以使用 cache-ref 元素来引用另外一个缓存。</span></span><br><span class="line"><span class="comment">    --&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 配置文件的参数问题</span></span><br><span class="line"><span class="comment">            使用ognl表达式可以讲表达式中的字符串动态的更换成想应的字符串类型</span></span><br><span class="line"><span class="comment">            #&#123;property,javaType=int,jdbcType=NUMERIC&#125;</span></span><br><span class="line"><span class="comment">            使用$&#123;xxx&#125;只是动态的插入一个字符串的值</span></span><br><span class="line"><span class="comment">     --&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 6.resultMap-mybatis中最重要和最关键的标签 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"S_Mybatis.z_z_MyBatis实例.javabean.BeanOne"</span> <span class="attr">id</span>=<span class="string">"myid"</span> &gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">            1.resultMap标签的属性 </span></span><br><span class="line"><span class="comment">                        type-指定结果集的实现类</span></span><br><span class="line"><span class="comment">                        id-指定这个结果集的唯一id标识</span></span><br><span class="line"><span class="comment">                        automapping-是否启用自动映射</span></span><br><span class="line"><span class="comment">                        extends-表示使用</span></span><br><span class="line"><span class="comment">        --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">            2.construction </span></span><br><span class="line"><span class="comment">                    标签-当javabean中含有无参数的构造函数的时候可以使用这个方法进行构造注入</span></span><br><span class="line"><span class="comment">         --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">constructor</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--注意当使用这个方法的时候 构造函数不能使用自动装箱的方法,也就是说int类型要写成Integer --&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">idArg</span> <span class="attr">column</span>=<span class="string">"name"</span> <span class="attr">javaType</span>=<span class="string">"String"</span> <span class="attr">jdbcType</span>=<span class="string">"VARCHAR"</span> /&gt;</span></span><br><span class="line">            <span class="comment">&lt;!-- 使用这个方法进行构造的时候要保证参数的顺序是按照自己定义的顺序的 --&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">arg</span> <span class="attr">column</span>=<span class="string">"name"</span> <span class="attr">javaType</span>=<span class="string">"String"</span> <span class="attr">jdbcType</span>=<span class="string">"VARCHAR"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">constructor</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- id 属性和result属性 这两个属性是相同的效果的只不过id属性表示的是主键二result表示的是一般的键 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">            3.id和result的变量属性</span></span><br><span class="line"><span class="comment">                    column-指定进行映射的列名称(就是使用mysql数据库进行查询操作最后上面出现的一列) </span></span><br><span class="line"><span class="comment">                    javaType-指定映射出来的java变量类型一般指定是基本的变量类型</span></span><br><span class="line"><span class="comment">                    property-指定需要映射的javabean的变量名称	 jdbcType-指定映射出来的数据变量类型</span></span><br><span class="line"><span class="comment">                    typeHandler-指定使用的转换器!!!必须在mybatis的配置文件中进行配置</span></span><br><span class="line"><span class="comment">        --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 使用参数注入的时候不必像构造注入的时候那样int类型必须转化成integer --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span> <span class="attr">column</span>=<span class="string">"name"</span> <span class="attr">javaType</span>=<span class="string">"String"</span> <span class="attr">property</span>=<span class="string">"name"</span> <span class="attr">jdbcType</span>=<span class="string">"VARCHAR"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"age"</span> <span class="attr">javaType</span>=<span class="string">"String"</span> <span class="attr">jdbcType</span>=<span class="string">"VARCHAR"</span> <span class="attr">property</span>=<span class="string">"age"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 4.设置一对多和一对一连级查询 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--</span></span><br><span class="line"><span class="comment">             这两个属性可以使用嵌套模式 当使用其那套模式的时候需要进行相关的属性设置</span></span><br><span class="line"><span class="comment">            通过外链接的方法时 必须的属性！！	</span></span><br><span class="line"><span class="comment">                    property - 设置对应结果集的javabean中的参数</span></span><br><span class="line"><span class="comment">                   javatype(一对一)-</span></span><br><span class="line"><span class="comment">                   oftyp(一对多)(数据库开启了自动映射)-返回结果集的集合或者使用一个resultMap</span></span><br><span class="line"><span class="comment">           通过sql嵌套方法时 必须！！		</span></span><br><span class="line"><span class="comment">                           property - 设置对应结果集的javabean中的参数</span></span><br><span class="line"><span class="comment">                           colomn - 使用关联的列 </span></span><br><span class="line"><span class="comment">                           select - 调用的sql语句</span></span><br><span class="line"><span class="comment">       --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 一对一连级查询  pro表示类中对应的参数--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">association</span> <span class="attr">property</span>=<span class="string">"list"</span> &gt;</span><span class="tag">&lt;/<span class="name">association</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 一对多连级查询方法这个方法其实和传统的使用方法其实是没有什么区别的只不过需要将其中的属性编程一个集合</span></span><br><span class="line"><span class="comment">        (resultMap属性)并且保证关联集合中的属性名名称对应的数据库列植是通过数据库的查询出来的列值而不是自己在sql语句中定义的列值</span></span><br><span class="line"><span class="comment">        --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"list"</span> <span class="attr">column</span>=<span class="string">"x"</span> <span class="attr">resultMap</span>=<span class="string">"myid"</span>&gt;</span><span class="tag">&lt;/<span class="name">collection</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">            property 		生成结果集中javabean对应的属性!!</span></span><br><span class="line"><span class="comment">           automapping  	自动映射 让得到的数据库列明和声明的结果集（参数名） 相同</span></span><br><span class="line"><span class="comment">           column  		进行一对多sql分层注入的时 决定使用哪一列进行判断!!</span></span><br><span class="line"><span class="comment">           columnPrefix  	允许我们在重复出现的字段名前加上一个统一的字符前缀- 一般不用</span></span><br><span class="line"><span class="comment">           fetchType 		可选的。 有效值是lazy和eager。 </span></span><br><span class="line"><span class="comment">                           如果存在，它将取代此映射的全局配置参数lazyLoadingEnabled。</span></span><br><span class="line"><span class="comment">           jdbctype  		在这个表格之前的所支持的 JDBC 类型列表中的类型。JDBC 类型是仅仅 </span></span><br><span class="line"><span class="comment">                           需要对插入, 更新和删除操作可能为空的列进行处理。</span></span><br><span class="line"><span class="comment">                           这是 JDBC 的需要, jdbcType 而不是 MyBatis 的。</span></span><br><span class="line"><span class="comment">                           如果你直接使用 JDBC 编程,你需要指定这个类型-但 仅仅对可能为空的值。</span></span><br><span class="line"><span class="comment">           javatype		一个 Java 类的完全限定名,或一个类型别名(参考上面内建类型别名的列 表) 。</span></span><br><span class="line"><span class="comment">                           如果你映射到一个 JavaBean,MyBatis 通常可以断定类型。</span></span><br><span class="line"><span class="comment">                           然而,如 javaType 果你映射到的是 HashMap,那么你应该明确地指定 javaType 来保证所需的 行为。</span></span><br><span class="line"><span class="comment">           notnullcolomn 	默认情况下，仅当映射到子对象的属性的列中的至少一列非空时才创建子对象。 </span></span><br><span class="line"><span class="comment">                           使用此属性，您可以通过指定哪些列必须具有值来更改此行为，</span></span><br><span class="line"><span class="comment">                           因此只有当任何这些列不为null时，MyBatis才会创建子对象。 </span></span><br><span class="line"><span class="comment">                           可以使用逗号作为分隔符指定多个列名称。 默认值：unset。</span></span><br><span class="line"><span class="comment">           resultMap		!!</span></span><br><span class="line"><span class="comment">           resultSet</span></span><br><span class="line"><span class="comment">           typeHandle</span></span><br><span class="line"><span class="comment">           select    		!!表示用那个映射id的语句-查询的功能将会依次的进行查询先使用外层的查询语句然后在使用后面的查询语句</span></span><br><span class="line"><span class="comment">            oftype			返回的集合的每一个元素的属性</span></span><br><span class="line"><span class="comment">        --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 使用resultMap鉴别器 -鉴别器是使用在一个result中的里面的case属性的值将会使用外层定义的colum的属性的值都转化成</span></span><br><span class="line"><span class="comment">              javaTye后进行比较如果成立就会使用.里面定义的resultMap处理注意这就说明了映射的属性必须和原来的参数兼容否则就是不匹配的</span></span><br><span class="line"><span class="comment">         --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">discriminator</span> <span class="attr">javaType</span>=<span class="string">"S_Mybatis.z_z_MyBatis实例.javabean.BeanOne"</span> <span class="attr">column</span>=<span class="string">"xxx"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">case</span> <span class="attr">value</span>=<span class="string">"1"</span> <span class="attr">resultMap</span>=<span class="string">"lll"</span>&gt;</span><span class="tag">&lt;/<span class="name">case</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">discriminator</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- !!!!解决mybatis加载的性能问题 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 解决办法使用延迟加载和使用非层级加载 在mybatis 的配置文件中进行相关的配置(这个配置方法是全局性的)</span></span><br><span class="line"><span class="comment">           当不是用全局性的变量的时候可以使用在xml属性中如(select)定义的属性fetchType(eager lazy-指定使用延迟加载)</span></span><br><span class="line"><span class="comment">         --&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"S_Mybatis.z_z_MyBatis实例.javabean.BeanOne"</span> <span class="attr">id</span>=<span class="string">"lll"</span> <span class="attr">extends</span>=<span class="string">"yyy"</span>&gt;</span><span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 4.Sql动态语句  ognl的标准查看截图  注意#&#123;xxx&#125;不是ognl表达式 使用方法见上面的parameter --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"xxx"</span> <span class="attr">parameterType</span>=<span class="string">"S_Mybatis.z_z_MyBatis实例.javabean.BeanOne"</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">                这里使用的ognl表达式</span></span><br><span class="line"><span class="comment">        表达式的功能异常的强大他可以直接使用在变量作用域(parameterType中的yyy)中定义的变量名称别切可以调用变量的相关方法</span></span><br><span class="line"><span class="comment">        --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- if就和java中的if语句插不多但是要注意使用转义字符-具体的自己查 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"name!=null"</span>&gt;</span><span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">choose</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">when</span> <span class="attr">test</span>=<span class="string">"name=null"</span>&gt;</span><span class="tag">&lt;/<span class="name">when</span>&gt;</span><span class="comment">&lt;!-- if else-if else--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">otherwise</span>&gt;</span><span class="tag">&lt;/<span class="name">otherwise</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">choose</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">where</span>&gt;</span><span class="comment">&lt;!-- 相当于 select语句中的where  当其中的条件语句完全成立的时候才加入 where语句--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"xxx"</span>&gt;</span><span class="tag">&lt;/<span class="name">if</span>&gt;</span><span class="comment">&lt;!-- 只用当之中的语句成立的时候才会动态的添加一个where否则不会添加where语句 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">where</span>&gt;</span><span class="comment">&lt;!-- 注意表达式中的ognl表达式中#相当于ActionContext. getContext();直接使用 参数就可以了 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 通用where语句增强版 prefix-表示这段代码块的前缀,prefixOVerrides-表示填充这段代码的分割属性 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">trim</span> <span class="attr">prefix</span>=<span class="string">"where"</span> <span class="attr">prefixOverrides</span>=<span class="string">""</span> <span class="attr">suffix</span>=<span class="string">""</span> <span class="attr">suffixOverrides</span>=<span class="string">""</span>&gt;</span><span class="tag">&lt;/<span class="name">trim</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 循环语句 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">foreach</span> <span class="attr">collection</span>=<span class="string">""</span> <span class="attr">close</span>=<span class="string">""</span> <span class="attr">open</span>=<span class="string">""</span>&gt;</span><span class="tag">&lt;/<span class="name">foreach</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">            collection - 一个数字或者list集合 </span></span><br><span class="line"><span class="comment">            item - 配置循环中的当前的元素</span></span><br><span class="line"><span class="comment">            index - 配置当前元素的下标</span></span><br><span class="line"><span class="comment">            open - close - 用什么元素将其中的 元素包裹起来</span></span><br><span class="line"><span class="comment">            separator - 各个元素的间隔符号</span></span><br><span class="line"><span class="comment">        --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 这个元素表示一个配置文件自己定义的上下文变量 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">bind</span> <span class="attr">name</span>=<span class="string">"xx"</span> <span class="attr">value</span>=<span class="string">"xxx"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!-- 参数传递方法 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"hehe"</span> <span class="attr">parameterType</span>=<span class="string">"o_EhCache缓存.ceshi.Javabean"</span> &gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 使用这个表达式直接将xxx对象或者map中的属性自动的注入进来 --&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- parameterType="xxx.xxx"-mybaits的内置对象实现自动注入相关的属性 --&gt;</span></span><br><span class="line">        select * from xxx where name =#&#123;id&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>SQL 映射文件有很少的几个顶级元素（按照它们应该被定义的顺序）：</p>
<ul>
<li>cache – 给定命名空间的缓存配置。</li>
<li>cache-ref – 其他命名空间缓存配置的引用。</li>
<li>resultMap – 是最复杂也是最强大的元素，用来描述如何从数据库结果集中来加载对象。</li>
<li>parameterMap – 已废弃！老式风格的参数映射。内联参数是首选,这个元素可能在将来被移除，这里不会记录。</li>
<li>sql – 可被其他语句引用的可重用语句块。</li>
<li>insert – 映射插入语句</li>
<li>update – 映射更新语句</li>
<li>delete – 映射删除语句</li>
<li>select – 映射查询语句</li>
</ul>
<h3 id="标签使用详解"><a href="#标签使用详解" class="headerlink" title="标签使用详解"></a>标签使用详解</h3><h4 id="select-insert-update-delete"><a href="#select-insert-update-delete" class="headerlink" title="select insert update delete"></a>select insert update delete</h4><p>selete标签相关的属性</p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>参数作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>在命名空间中唯一的标识符，可以被用来引用这条语句。</td>
</tr>
<tr>
<td>parameterType</td>
<td>将会传入这条语句的参数类的完全限定名或别名。这个属性是可选的，因为 MyBatis 可以通过 TypeHandler 推断出具体传入语句的参数，默认值为 unset。</td>
</tr>
<tr>
<td>parameterMap</td>
<td>这是引用外部 parameterMap 的已经被废弃的方法。使用内联参数映射和 parameterType 属性。</td>
</tr>
<tr>
<td>resultType</td>
<td>从这条语句中返回的期望类型的类的完全限定名或别名。注意如果是集合情形，那应该是集合可以包含的类型，而不能是集合本身。使用 resultType 或 resultMap，但不能同时使用。</td>
</tr>
<tr>
<td>resultMap</td>
<td>外部 resultMap 的命名引用。结果集的映射是 MyBatis 最强大的特性，对其有一个很好的理解的话，许多复杂映射的情形都能迎刃而解。使用 resultMap 或 resultType，但不能同时使用。</td>
</tr>
<tr>
<td>flushCache</td>
<td>将其设置为 true，任何时候只要语句被调用，都会导致本地缓存和二级缓存都会被清空，默认值：false。</td>
</tr>
<tr>
<td>useCache</td>
<td>将其设置为 true，将会导致本条语句的结果被二级缓存，默认值：对 select 元素为 true。</td>
</tr>
<tr>
<td>timeout</td>
<td>这个设置是在抛出异常之前，驱动程序等待数据库返回请求结果的秒数。默认值为 unset（依赖驱动）。</td>
</tr>
<tr>
<td>fetchSize</td>
<td>这是尝试影响驱动程序每次批量返回的结果行数和这个设置值相等。默认值为 unset（依赖驱动）。</td>
</tr>
<tr>
<td>statementType</td>
<td>STATEMENT，PREPARED 或 CALLABLE 的一个。这会让 MyBatis 分别使用 Statement，PreparedStatement 或 CallableStatement，默认值：PREPARED。</td>
</tr>
<tr>
<td>resultSetType</td>
<td>FORWARD_ONLY，SCROLL_SENSITIVE 或 SCROLL_INSENSITIVE 中的一个，默认值为 unset （依赖驱动）。</td>
</tr>
<tr>
<td>databaseId</td>
<td>如果配置了 databaseIdProvider，MyBatis 会加载所有的不带 databaseId 或匹配当前 databaseId的语句；如果带或者不带的语句都有，则不带的会被忽略。</td>
</tr>
<tr>
<td>resultOrdered</td>
<td>这个设置仅针对嵌套结果 select 语句适用：如果为 true，就是假设包含了嵌套结果集或是分组了，这样的话当返回一个主结果行的时候，就不会发生有对前面结果集的引用的情况。这就使得在获取嵌套的结果集的时候不至于导致内存不够用。默认值：false。</td>
</tr>
<tr>
<td>resultSets</td>
<td>这个设置仅对多结果集的情况适用，它将列出语句执行后返回的结果集并每个结果集给一个名称，名称是逗号分隔的。</td>
</tr>
</tbody>
</table>
<h4 id="insert-update-delete属性相关标签"><a href="#insert-update-delete属性相关标签" class="headerlink" title="insert update delete属性相关标签"></a>insert update delete属性相关标签</h4><table>
<thead>
<tr>
<th>参数名</th>
<th>参数作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>命名空间中的唯一标识符，可被用来代表这条语句。</td>
</tr>
<tr>
<td>parameterType</td>
<td>将要传入语句的参数的完全限定类名或别名。这个属性是可选的，因为 MyBatis 可以通过 TypeHandler</td>
<td>推断出具体传入语句的参数，默认值为 unset。</td>
</tr>
<tr>
<td>parameterMap</td>
<td>这是引用外部 parameterMap 的已经被废弃的方法。使用内联参数映射和 parameterType 属性。</td>
</tr>
<tr>
<td>flushCache</td>
<td>将其设置为 true，任何时候只要语句被调用，都会导致本地缓存和二级缓存都会被清空，默认值：true（对应插入、更新和删除语句）。</td>
</tr>
<tr>
<td>timeout</td>
<td>这个设置是在抛出异常之前，驱动程序等待数据库返回请求结果的秒数。默认值为 unset（依赖驱动）。</td>
</tr>
<tr>
<td>statementType</td>
<td>STATEMENT，PREPARED 或 CALLABLE 的一个。这会让 MyBatis 分别使用 Statement，PreparedStatement 或 CallableStatement，默认值：PREPARED。</td>
</tr>
<tr>
<td>useGeneratedKeys</td>
<td>（仅对 insert 和 update 有用）这会令 MyBatis 使用 JDBC 的 getGeneratedKeys</td>
<td>方法来取出由数据库内部生成的主键（比如：像 MySQL 和 SQL Server 这样的关系数据库管理系统的自动递增字段），默认值：false。</td>
</tr>
<tr>
<td>keyProperty</td>
<td>（仅对 insert 和 update 有用）唯一标记一个属性，MyBatis 会通过 getGeneratedKeys 的返回值或者通过 insert 语句的 selectKey 子元素设置它的键值，默认：unset。如果希望得到多个生成的列，也可以是逗号分隔的属性名称列表。</td>
</tr>
<tr>
<td>keyColumn</td>
<td>（仅对 insert 和 update 有用）通过生成的键值设置表中的列名，这个设置仅在某些数据库（像 PostgreSQL）是必须的，当主键列不是表中的第一列的时候需要设置。如果希望得到多个生成的列，也可以是逗号分隔的属性名称列表。</td>
</tr>
<tr>
<td>databaseId</td>
<td>如果配置了 databaseIdProvider，MyBatis 会加载所有的不带 databaseId 或匹配当前 databaseId 的语句；如果带或者不带的语句都有，则不带的会被忽略。</td>
</tr>
</tbody>
</table>
<p><strong>注意</strong>：useGeneratedKeys keyProperty keyColumn parameterType主要用来进行 自增加主键的 回调操作，就是当进行插入操作的之后，自动生成的主键重新注入到传入的 parameterType对应的javabean中，（底层使用jbdc的getGeneratedKeys方法）</p>
<h4 id="selectKey-和-keyProperty-keyColumn-结合使用进行主键回填操作"><a href="#selectKey-和-keyProperty-keyColumn-结合使用进行主键回填操作" class="headerlink" title="selectKey 和 keyProperty keyColumn 结合使用进行主键回填操作"></a>selectKey 和 keyProperty keyColumn 结合使用进行主键回填操作</h4><p>在insert 和 update 标签中才会有用的一个标签   会在执行语句之前先进行一次查询，并将得到的数据放入 keyProperty属性指定名称的字段中（调用传入的变量的keyproperty指定名称的地方）作为后面进行操作的数据，一般用在 对于不支持自动生成类型的数据库或可能不支持自动生成主键 JDBC 驱动，来生成主键。</p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>参数作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>keyProperty</td>
<td>selectKey 语句结果应该被设置的目标属性。如果希望得到多个生成的列，也可以是逗号分隔的属性名称列表。</td>
</tr>
<tr>
<td>keyColumn</td>
<td>匹配属性的返回结果集中的列名称。如果希望得到多个生成的列，也可以是逗号分隔的属性名称列表。   注意 Property和Column一一对应</td>
</tr>
<tr>
<td>resultType</td>
<td>结果的类型。MyBatis 通常可以推算出来，但是为了更加确定写上也不会有什么问题。MyBatis 允许任何简单类型用作主键的类型，包括字符串。如果希望作用于多个生成的列，则可以使用一个包含期望属性的 Object 或一个 Map。</td>
</tr>
<tr>
<td>order</td>
<td>这可以被设置为 BEFORE 或 AFTER。如果设置为 BEFORE，那么它会首先选择主键，设置 keyProperty 然后执行插入语句。如果设置为 AFTER，那么先执行插入语句，然后是 selectKey 元素 – 这和像 Oracle 的数据库相似，在插入语句内部可能有嵌入索引调用。</td>
</tr>
<tr>
<td>statementType</td>
<td>与前面相同，MyBatis 支持 STATEMENT，PREPARED 和 CALLABLE 语句的映射类型，分别代表 PreparedStatement 和 CallableStatement 类型。</td>
</tr>
</tbody>
</table>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">"insertAuthor"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">selectKey</span> <span class="attr">keyProperty</span>=<span class="string">"id"</span> <span class="attr">resultType</span>=<span class="string">"int"</span> <span class="attr">order</span>=<span class="string">"BEFORE"</span>&gt;</span></span><br><span class="line">        select CAST(RANDOM()*1000000 as INTEGER) a from SYSIBM.SYSDUMMY1</span><br><span class="line">    <span class="tag">&lt;/<span class="name">selectKey</span>&gt;</span></span><br><span class="line">    insert into Author</span><br><span class="line">    (id, username, password, email,bio, favourite_section)</span><br><span class="line">    values</span><br><span class="line">    (#&#123;id&#125;, #&#123;username&#125;, #&#123;password&#125;, #&#123;email&#125;, #&#123;bio&#125;, #&#123;favouriteSection,jdbcType=VARCHAR&#125;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="sql标签和include-标签"><a href="#sql标签和include-标签" class="headerlink" title="sql标签和include 标签"></a>sql标签和include 标签</h4><p>sql和include 标签一般进行组合使用，形成各种参数化配置</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">sql</span> <span class="attr">id</span>=<span class="string">"userColumns"</span>&gt;</span> $&#123;alias&#125;.id,$&#123;alias&#125;.username,$&#123;alias&#125;.password <span class="tag">&lt;/<span class="name">sql</span>&gt;</span><span class="comment">&lt;!--设置相关的各种属性--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"selectUsers"</span> <span class="attr">resultType</span>=<span class="string">"map"</span>&gt;</span><span class="comment">&lt;!--include标签动态的传入相关的属性--&gt;</span></span><br><span class="line">  select</span><br><span class="line">    <span class="tag">&lt;<span class="name">include</span> <span class="attr">refid</span>=<span class="string">"userColumns"</span>&gt;</span><span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"alias"</span> <span class="attr">value</span>=<span class="string">"t1"</span>/&gt;</span><span class="tag">&lt;/<span class="name">include</span>&gt;</span>,</span><br><span class="line">    <span class="tag">&lt;<span class="name">include</span> <span class="attr">refid</span>=<span class="string">"userColumns"</span>&gt;</span><span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"alias"</span> <span class="attr">value</span>=<span class="string">"t2"</span>/&gt;</span><span class="tag">&lt;/<span class="name">include</span>&gt;</span></span><br><span class="line">  from some_table t1</span><br><span class="line">    cross join some_table t2</span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="结果集映射方法"><a href="#结果集映射方法" class="headerlink" title="结果集映射方法"></a>结果集映射方法</h4><p>查询语句</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- Very Complex Statement --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"selectBlogDetails"</span> <span class="attr">resultMap</span>=<span class="string">"detailedBlogResultMap"</span>&gt;</span></span><br><span class="line">    select</span><br><span class="line">    B.id as blog_id,</span><br><span class="line">    B.title as blog_title,</span><br><span class="line">    B.author_id as blog_author_id,</span><br><span class="line">    A.id as author_id,</span><br><span class="line">    A.username as author_username,</span><br><span class="line">    A.password as author_password,</span><br><span class="line">    A.email as author_email,</span><br><span class="line">    A.bio as author_bio,</span><br><span class="line">    A.favourite_section as author_favourite_section,</span><br><span class="line">    P.id as post_id,</span><br><span class="line">    P.blog_id as post_blog_id,</span><br><span class="line">    P.author_id as post_author_id,</span><br><span class="line">    P.created_on as post_created_on,</span><br><span class="line">    P.section as post_section,</span><br><span class="line">    P.subject as post_subject,</span><br><span class="line">    P.draft as draft,</span><br><span class="line">    P.body as post_body,</span><br><span class="line">    C.id as comment_id,</span><br><span class="line">    C.post_id as comment_post_id,</span><br><span class="line">    C.name as comment_name,</span><br><span class="line">    C.comment as comment_text,</span><br><span class="line">    T.id as tag_id,</span><br><span class="line">    T.name as tag_name</span><br><span class="line">    from Blog B</span><br><span class="line">    left outer join Author A on B.author_id = A.id</span><br><span class="line">    left outer join Post P on B.id = P.blog_id</span><br><span class="line">    left outer join Comment C on P.id = C.post_id</span><br><span class="line">    left outer join Post_Tag PT on PT.post_id = P.id</span><br><span class="line">    left outer join Tag T on PT.tag_id = T.id</span><br><span class="line">    where B.id = #&#123;id&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>结果集</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- Very Complex Result Map --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">id</span>=<span class="string">"detailedBlogResultMap"</span> <span class="attr">type</span>=<span class="string">"Blog"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">constructor</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">idArg</span> <span class="attr">column</span>=<span class="string">"blog_id"</span> <span class="attr">javaType</span>=<span class="string">"int"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">constructor</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"title"</span> <span class="attr">column</span>=<span class="string">"blog_title"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">association</span> <span class="attr">property</span>=<span class="string">"author"</span> <span class="attr">javaType</span>=<span class="string">"Author"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span> <span class="attr">property</span>=<span class="string">"id"</span> <span class="attr">column</span>=<span class="string">"author_id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"username"</span> <span class="attr">column</span>=<span class="string">"author_username"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"password"</span> <span class="attr">column</span>=<span class="string">"author_password"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"email"</span> <span class="attr">column</span>=<span class="string">"author_email"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"bio"</span> <span class="attr">column</span>=<span class="string">"author_bio"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"favouriteSection"</span> <span class="attr">column</span>=<span class="string">"author_favourite_section"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">association</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"posts"</span> <span class="attr">ofType</span>=<span class="string">"Post"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span> <span class="attr">property</span>=<span class="string">"id"</span> <span class="attr">column</span>=<span class="string">"post_id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"subject"</span> <span class="attr">column</span>=<span class="string">"post_subject"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">association</span> <span class="attr">property</span>=<span class="string">"author"</span> <span class="attr">javaType</span>=<span class="string">"Author"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"comments"</span> <span class="attr">ofType</span>=<span class="string">"Comment"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">id</span> <span class="attr">property</span>=<span class="string">"id"</span> <span class="attr">column</span>=<span class="string">"comment_id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">collection</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"tags"</span> <span class="attr">ofType</span>=<span class="string">"Tag"</span> &gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">id</span> <span class="attr">property</span>=<span class="string">"id"</span> <span class="attr">column</span>=<span class="string">"tag_id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">collection</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">discriminator</span> <span class="attr">javaType</span>=<span class="string">"int"</span> <span class="attr">column</span>=<span class="string">"draft"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">case</span> <span class="attr">value</span>=<span class="string">"1"</span> <span class="attr">resultType</span>=<span class="string">"DraftPost"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">discriminator</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">collection</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="resultmap标签"><a href="#resultmap标签" class="headerlink" title="resultmap标签"></a>resultmap标签</h4><blockquote>
<p>表示一个映射结果集</p>
</blockquote>
<p>相关属性：</p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>参数作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>当前命名空间中的一个唯一标识，用于标识一个result map.</td>
</tr>
<tr>
<td>type</td>
<td>类的全限定名, 或者一个类型别名 (内置的别名可以参考上面的表格).</td>
</tr>
<tr>
<td>autoMapping</td>
<td>如果设置这个属性，MyBatis将会为这个ResultMap开启或者关闭自动映射。这个属性会覆盖全局的属性autoMappingBehavior。默认值为：unset。</td>
</tr>
</tbody>
</table>
<h4 id="resultmap标签子标签"><a href="#resultmap标签子标签" class="headerlink" title="resultmap标签子标签"></a>resultmap标签子标签</h4><p>id&amp;result设置对应结果集中类的各种参数，注意要有set方法，区别 id 表示的标识属性（一般就是表的主键）</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">id</span> <span class="attr">property</span>=<span class="string">"id"</span> <span class="attr">column</span>=<span class="string">"post_id"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"subject"</span> <span class="attr">column</span>=<span class="string">"post_subject"</span>/&gt;</span></span><br></pre></td></tr></table></figure>
<p>相关属性</p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>参数作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>property</td>
<td>映射到列结果的字段或属性。如果匹配的是存在的,和给定名称相同 的 JavaBeans 的属性,那么就会使用。否则 MyBatis 将会寻找给定名称 property 的字段。这两种情形你可以使用通常点式的复杂属性导航。比如,你 可以这样映射一些东西: “username” ,或者映射到一些复杂的东西: “address.street.number” 。</td>
</tr>
<tr>
<td>column</td>
<td>从数据库中得到的列名,或者是列名的重命名标签。这也是通常和会 传递给 resultSet.getString(columnName)方法参数中相同的字符串。</td>
</tr>
<tr>
<td>javaType</td>
<td>一个 Java 类的完全限定名,或一个类型别名(参考上面内建类型别名 的列表) 。如果你映射到一个 JavaBean,MyBatis 通常可以断定类型。 然而,如果你映射到的是 HashMap,那么你应该明确地指定 javaType 来保证所需的行为。</td>
</tr>
<tr>
<td>jdbcType</td>
<td>在这个表格之后的所支持的 JDBC 类型列表中的类型。JDBC 类型是仅 仅需要对插入,更新和删除操作可能为空的列进行处理。这是 JDBC jdbcType 的需要,而不是 MyBatis 的。如果你直接使用 JDBC 编程,你需要指定 这个类型-但仅仅对可能为空的值。</td>
</tr>
<tr>
<td>typeHandler</td>
<td>我们在前面讨论过默认的类型处理器。使用这个属性,你可以覆盖默 认的类型处理器。这个属性值是类的完全限定名或者是一个类型处理 器的实现,或者是类型别名。</td>
</tr>
</tbody>
</table>
<h4 id="constructor标签"><a href="#constructor标签" class="headerlink" title="constructor标签"></a>constructor标签</h4><p>constructor标签 使用构造方法进行注入，注意必须提供相对应的构造方法，参数的书写顺序和构造函数的顺序相同（3.4.3起可以不同但是要对构造函数添加@Param注解，和启用useActualParamname）</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">constructor</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">idArg</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">javaType</span>=<span class="string">"int"</span> <span class="attr">name</span>=<span class="string">"id"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">arg</span> <span class="attr">column</span>=<span class="string">"age"</span> <span class="attr">javaType</span>=<span class="string">"_int"</span> <span class="attr">name</span>=<span class="string">"age"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">arg</span> <span class="attr">column</span>=<span class="string">"username"</span> <span class="attr">javaType</span>=<span class="string">"String"</span> <span class="attr">name</span>=<span class="string">"username"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">constructor</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>相关属性</p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>参数作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>column</td>
<td>来自数据库的类名,或重命名的列标签。这和通常传递给 resultSet.getString(columnName)方法的字符串是相同的。</td>
</tr>
<tr>
<td>javaType</td>
<td>一个Java 类的完全限定名,或一个类型别名(参考上面内建类型别名的列表)。如果你映射到一个 JavaBean,MyBatis 通常可以断定类型。然而,如 果你映射到的是 HashMap,那么你应该明确地指定 javaType 来保证所需的 行为。</td>
</tr>
<tr>
<td>jdbcType</td>
<td>在这个表格之前的所支持的 JDBC 类型列表中的类型。JDBC 类型是仅仅 需要对插入, 更新和删除操作可能为空的列进行处理。这是 JDBC 的需要, jdbcType 而不是 MyBatis 的。如果你直接使用 JDBC 编程,你需要指定这个类型-但 仅仅对可能为空的值。</td>
</tr>
<tr>
<td>typeHandler</td>
<td>我们在前面讨论过默认的类型处理器。使用这个属性,你可以覆盖默认的 类型处理器。这个属性值是类的完全限定名或者是一个类型处理器的实现, 或者是类型别名。</td>
</tr>
<tr>
<td>select</td>
<td>用于加载复杂类型属性的映射语句的ID,从column中检索出来的数据，将作为此select语句的参数。具体请参考Association标签。</td>
</tr>
<tr>
<td>resultMap</td>
<td>ResultMap的ID，可以将嵌套的结果集映射到一个合适的对象树中，功能和select属性相似，它可以实现将多表连接操作的结果映射成一个单一的ResultSet。这样的ResultSet将会将包含重复或部分数据重复的结果集正确的映射到嵌套的对象树中。为了实现它, MyBatis允许你 “串联” ResultMap,以便解决嵌套结果集的问题。想了解更多内容，请参考下面的Association元素。</td>
</tr>
<tr>
<td>name</td>
<td>构造方法形参的名字。通过指定具体的名字你可以以任意顺序写入arg元素。参看上面的解释。从3.4.3版本起。</td>
</tr>
</tbody>
</table>
<h4 id="cache-二级缓存"><a href="#cache-二级缓存" class="headerlink" title="cache-二级缓存"></a>cache-二级缓存</h4><p>默认情况下只是默认开启了一级缓存，也就是对同一个sqlsession缓存相关的各种数据，开起二级缓存将会在sqlsessionFactory级别进行缓存，缓存的数据所有的sqlsession共享</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">cache</span> <span class="attr">eviction</span>=<span class="string">"FIFO"</span> <span class="attr">flushInterval</span>=<span class="string">"60000"</span> <span class="attr">size</span>=<span class="string">"512"</span>  <span class="attr">readOnly</span>=<span class="string">"true"</span>/&gt;</span></span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th>参数名</th>
<th>参数作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>eviction</td>
<td>回收策略，LRU – 最近最少使用的:移除最长时间不被使用的对象。 FIFO – 先进先出:按对象进入缓存的顺序来移除它们。 SOFT – 软引用:移除基于垃圾回收器状态和软引用规则的对象。WEAK – 弱引用:更积极地移除基于垃圾收集器状态和弱引用规则的对象。</td>
</tr>
<tr>
<td>flushInterval(刷新间隔)</td>
<td>可以被设置为任意的正整数,而且它们代表一个合理的毫秒 形式的时间段。默认情况是不设置,也就是没有刷新间隔,缓存仅仅调用语句时刷新。</td>
</tr>
<tr>
<td>size(引用数目)</td>
<td>可以被设置为任意正整数,要记住你缓存的对象数目和你运行环境的 可用内存资源数目。默认值是 1024</td>
</tr>
<tr>
<td>readOnly(只读)</td>
<td>属性可以被设置为 true 或 false。只读的缓存会给所有调用者返回缓 存对象的相同实例。因此这些对象不能被修改。这提供了很重要的性能优势。可读写的缓存 会返回缓存对象的拷贝(通过序列化) 。这会慢一些,但是安全,因此默认是 false。</td>
</tr>
</tbody>
</table>
<h4 id="引申mybatis使用自定义缓存"><a href="#引申mybatis使用自定义缓存" class="headerlink" title="引申mybatis使用自定义缓存"></a>引申mybatis使用自定义缓存</h4><p>除了这些自定义缓存的方式, 你也可以通过实现你自己的缓存或为其他第三方缓存方案 创建适配器来完全覆盖缓存行为。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">cache</span> <span class="attr">type</span>=<span class="string">"com.domain.something.MyCustomCache"</span>/&gt;</span></span><br></pre></td></tr></table></figure>
<p>这个示 例展 示了 如何 使用 一个 自定义 的缓 存实 现。type 属 性指 定的 类必 须实现 org.mybatis.cache.Cache 接口。这个接口是 MyBatis 框架中很多复杂的接口之一,但是简单 给定它做什么就行。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">Cache</span> </span>&#123;</span><br><span class="line">    <span class="function">String <span class="title">getId</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">int</span> <span class="title">getSize</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">putObject</span><span class="params">(Object key, Object value)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="function">Object <span class="title">getObject</span><span class="params">(Object key)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">boolean</span> <span class="title">hasKey</span><span class="params">(Object key)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="function">Object <span class="title">removeObject</span><span class="params">(Object key)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">clear</span><span class="params">()</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>要配置你的缓存, 简单和公有的 JavaBeans 属性来配置你的缓存实现, 而且是通过 cache 元素来传递属性, 比如, 下面代码会在你的缓存实现中调用一个称为 “setCacheFile(String file)” 的方法:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">cache</span> <span class="attr">type</span>=<span class="string">"com.domain.something.MyCustomCache"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"cacheFile"</span> <span class="attr">value</span>=<span class="string">"/tmp/my-custom-cache.tmp"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">cache</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>你可以使用所有简单类型作为 JavaBeans 的属性,MyBatis 会进行转换。 And you can specify a placeholder(e.g. ${cache.file}) to replace value defined at configuration properties.</p>
<p>从3.4.2版本开始，MyBatis已经支持在所有属性设置完毕以后可以调用一个初始化方法。如果你想要使用这个特性，请在你的自定义缓存类里实现 org.apache.ibatis.builder.InitializingObject 接口。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">InitializingObject</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">initialize</span><span class="params">()</span> <span class="keyword">throws</span> Exception</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/算法阶段性小结(一)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/算法阶段性小结(一)/" itemprop="url">未命名</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:22:37+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="1-尾部的0"><a href="#1-尾部的0" class="headerlink" title="1. 尾部的0"></a>1. 尾部的0</h3><p>设计一个算法，计算出n阶乘中尾部零的个数</p>
<p>思路：数据中如果有5的倍数的话就多一个0,25的倍数话多两个0,但是注意了如果通用算了5的倍数的时候其实也算了25的倍数所以思路很简单，就是算算到n为止有多少5,25,125…个倍数就行了</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>&#123;</span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * @param n: An integer</span></span><br><span class="line"><span class="comment">     * @return: An integer, denote the number of trailing zeros in n!</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">trailingZeros</span><span class="params">(<span class="keyword">long</span> n)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">long</span> count=<span class="number">0</span>;<span class="comment">//一定是long~~~~</span></span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;Math.pow(<span class="number">5</span>,i)&lt;=n;i++)</span><br><span class="line">            count+=n/(<span class="keyword">long</span>)Math.pow(<span class="number">5</span>,i);</span><br><span class="line">        <span class="keyword">return</span> count;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>反思，好久没有动脑了，只是看到了表面的东西，没有深入思考，要恢复以前对数字敏感的状态</p>
<h3 id="2-提及数字"><a href="#2-提及数字" class="headerlink" title="2. 提及数字"></a>2. 提及数字</h3><p>计算数字k在0到n中的出现的次数，k可能是0~9的一个数值</p>
<p>基本的排列组合 比如 123 这个数组要算 1出现的个数 就算 ××1 ×1× 1×× 分别有多少个就可以了，但是又很多的边界问题比如</p>
<p>比如：001可以存在，但是如果这个数组只有一位比如 9 那么就不能有 01  </p>
<p>验证一下为什么这么做对，因为 在计算××1 的时候 想 ×11 和 111 这种情况只计算了一次，所以再计算×1× 和 1×× 的时候就不需要去重了</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Code2</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Code2 main2 = <span class="keyword">new</span> Code2();</span><br><span class="line">        <span class="keyword">long</span> nowTime = <span class="keyword">new</span> Date().getTime();</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">10000</span>; i &lt; <span class="number">99999</span>; i++) &#123;</span><br><span class="line">            main2.digitCounts3(<span class="number">2</span>,i);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">long</span> endTime = <span class="keyword">new</span> Date().getTime();</span><br><span class="line">        System.out.println(endTime - nowTime);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 复杂做法，使用计算法</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">digitCounts</span><span class="params">(<span class="keyword">int</span> k, <span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> item;</span><br><span class="line">        <span class="keyword">int</span> beforeNumber;</span><br><span class="line">        <span class="keyword">int</span> base = <span class="number">10</span>;</span><br><span class="line">        <span class="keyword">int</span> all = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">do</span> &#123;</span><br><span class="line">            beforeNumber = n / base * base;</span><br><span class="line">            item = (n - beforeNumber) / (base / <span class="number">10</span>);</span><br><span class="line">            <span class="keyword">if</span> (item &gt; k) &#123;</span><br><span class="line">                all += (n / base + <span class="number">1</span>) * (base / <span class="number">10</span>);</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (item == k) &#123;</span><br><span class="line">                all += (n / base) * (base / <span class="number">10</span>) + (n % (base / <span class="number">10</span>) + <span class="number">1</span>);<span class="comment">// 1 12 这种情况下注意有全零的数字   21345这个数据</span></span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                all += (n / base) * (base / <span class="number">10</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            base *= <span class="number">10</span>;</span><br><span class="line">        &#125; <span class="keyword">while</span> (beforeNumber != <span class="number">0</span>);</span><br><span class="line">        <span class="keyword">if</span> (k == <span class="number">0</span> &amp;&amp; base &gt; <span class="number">100</span>) &#123;<span class="comment">//01 02 不算数</span></span><br><span class="line">            all -= base / <span class="number">100</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> all;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//简单暴力方法</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">digitCounts3</span><span class="params">(<span class="keyword">int</span> k, <span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// write your code here</span></span><br><span class="line">        <span class="keyword">int</span> sum=<span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;=n;i++)&#123;</span><br><span class="line">            <span class="keyword">int</span> num=i;</span><br><span class="line">            <span class="keyword">while</span>(num/<span class="number">10</span>!=<span class="number">0</span>)&#123;</span><br><span class="line">                <span class="keyword">if</span>(num%<span class="number">10</span>==k)&#123;</span><br><span class="line">                    sum++;</span><br><span class="line">                &#125;</span><br><span class="line">                num=num/<span class="number">10</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(num==k)</span><br><span class="line">                sum++;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> sum;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>反思：思路要灵活重要的是脑子的反应要迅速，这道题目不难要 注意边界问题，为什么这么做正确的原因区间冗余是非常重要的</p>
<h3 id="3-丑数"><a href="#3-丑数" class="headerlink" title="3. 丑数"></a>3. 丑数</h3><p>设计一个算法，找出只含素因子2，3，5 的第 n 小的数。</p>
<p>符合条件的数如：1, 2, 3, 4, 5, 6, 8, 9, 10, 12…</p>
<p>这道题使用递推的思想最好，高级递推（有状态的递推）</p>
<p>有题目可以知道的  最开始我的思路一个丑数×2,×3，×5，分别得到下一个但是发现这样其实是错误的，比如3×3&lt;2*5,那么10会排在9的前面，所以我们要记录这个丑数被谁乘过，然后从中挑选出最小的一个</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">LeetLintCode01_</span>丑数 </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Code4 code4 = <span class="keyword">new</span> Code4();</span><br><span class="line">        System.out.println(code4.nthUglyNumber3(<span class="number">100</span>));</span><br><span class="line">        System.out.println(<span class="keyword">new</span> LeetLintCode01_丑数().nthSuperUglyNumber(<span class="number">6</span>,<span class="keyword">new</span> <span class="keyword">int</span>[]&#123;<span class="number">2</span>&#125;));</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">nthSuperUglyNumber</span><span class="params">(<span class="keyword">int</span> n, <span class="keyword">int</span>[] primes)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// write your code here</span></span><br><span class="line">        <span class="keyword">int</span>[] ugarr = <span class="keyword">new</span> <span class="keyword">int</span>[n];</span><br><span class="line">        ugarr[<span class="number">0</span>] = <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">int</span>[] item = <span class="keyword">new</span> <span class="keyword">int</span>[primes.length];<span class="comment">//分别对应的2,3,5 的被乘数的下标</span></span><br><span class="line"><span class="comment">//        int[] itemx= new int[3];//分别对应2,3,5 的乘数</span></span><br><span class="line"><span class="comment">//        itemx[0]=2;</span></span><br><span class="line"><span class="comment">//        itemx[1]=3;</span></span><br><span class="line"><span class="comment">//        itemx[2]=5;</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a = <span class="number">1</span>; a &lt; ugarr.length; a++) &#123;</span><br><span class="line">            <span class="keyword">int</span> index=<span class="number">0</span>;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> b = <span class="number">0</span>; b &lt; primes.length; b++) &#123;</span><br><span class="line">                <span class="keyword">if</span> (ugarr[item[b]]*primes[b]&lt;ugarr[item[index]]*primes[index])&#123;</span><br><span class="line">                    index=b;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> b = <span class="number">0</span>; b &lt;  primes.length; b++) &#123;</span><br><span class="line">                <span class="keyword">if</span> (b!=index&amp;&amp;ugarr[item[b]]*primes[b]==ugarr[item[index]]*primes[index])&#123;</span><br><span class="line">                    item[b]++;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            ugarr[a]=ugarr[item[index]]*primes[index];</span><br><span class="line">            item[index]++;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> ugarr[n - <span class="number">1</span>];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="4-第k大元素"><a href="#4-第k大元素" class="headerlink" title="4. 第k大元素"></a>4. 第k大元素</h3><p>在数组中找到第k大的元素，很简单，快速排序的应用，每一次查拆分其实是将数据进行了一次分类，可以归纳到，分治，递归的思想上，主要是要注意使用快排的时候的边界问题</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Code5</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">kthLargestElement</span><span class="params">(<span class="keyword">int</span> k, <span class="keyword">int</span>[] nums)</span> </span>&#123;</span><br><span class="line">        k = k - <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">int</span> index = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> a = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> b = nums.length - <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">while</span> (<span class="keyword">true</span>) &#123;</span><br><span class="line">            <span class="keyword">int</span> start = a;</span><br><span class="line">            <span class="keyword">int</span> end = b;</span><br><span class="line">            index = nums[start];</span><br><span class="line">            <span class="keyword">while</span> (start != end) &#123;</span><br><span class="line">                <span class="keyword">while</span> (nums[end] &lt; index &amp;&amp; start != end) &#123;</span><br><span class="line">                    end--;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (start != end) &#123;</span><br><span class="line">                    nums[start] = nums[end];</span><br><span class="line">                    start++;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">while</span> (nums[start] &gt; index &amp;&amp; start != end) &#123;</span><br><span class="line">                    start++;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (start != end) &#123;</span><br><span class="line">                    nums[end] = nums[start];</span><br><span class="line">                    end--;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            nums[start] = index;</span><br><span class="line">            <span class="keyword">if</span> (start &gt; k) &#123;</span><br><span class="line">                b = start - <span class="number">1</span>;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (start &lt; k) &#123;</span><br><span class="line">                a = start + <span class="number">1</span>;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="keyword">return</span> nums[start];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="5-旋转字符串"><a href="#5-旋转字符串" class="headerlink" title="5. 旋转字符串"></a>5. 旋转字符串</h3><p>给定一个字符串和一个偏移量，根据偏移量旋转字符串(从左向右旋转),这个问题关键是截枝，一个字符串asd 其实反转 asd.length步就变回原来的了，所以没必要就移动n步，这个地方坑住我了。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.Arrays;</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> str:    An array of char</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> offset: An integer</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span>: nothing</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">rotateString</span><span class="params">(<span class="keyword">char</span>[] str, <span class="keyword">int</span> offset)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (str.length == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        offset = offset % str.length;</span><br><span class="line">        <span class="comment">// write your code here</span></span><br><span class="line">        <span class="keyword">while</span> (offset &gt; <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">char</span> end = str[str.length - <span class="number">1</span>];</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> a = str.length - <span class="number">1</span>; a &gt; <span class="number">0</span>; a--) &#123;</span><br><span class="line">                str[a] = str[a - <span class="number">1</span>];</span><br><span class="line">            &#125;</span><br><span class="line">            str[<span class="number">0</span>] = end;</span><br><span class="line">            offset--;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="6-带最小值操作的栈"><a href="#6-带最小值操作的栈" class="headerlink" title="6. 带最小值操作的栈"></a>6. 带最小值操作的栈</h3><p>实现一个带有取最小值min方法的栈，min方法将返回当前栈中的最小值。</p>
<p>你实现的栈将支持push，pop 和 min 操作，所有操作要求都在O(1)时间内完成。</p>
<p>这个问题其实就是在push的时候每次都记住min的直并且每次pop操作动态更新就好了</p>
<p>收获主要就是不能单单的看到表象，更应该深入的数据中</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MinStack</span> </span>&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> Deque&lt;Integer&gt; mq = <span class="keyword">new</span> LinkedList&lt;&gt;();</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> Deque&lt;Integer&gt; min = <span class="keyword">new</span> LinkedList&lt;&gt;();</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">MinStack</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">// do intialization if necessary</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * @param number: An integer</span></span><br><span class="line"><span class="comment">     * @return: nothing</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">push</span><span class="params">(<span class="keyword">int</span> number)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// write your code here</span></span><br><span class="line">        <span class="keyword">if</span> (min.size() == <span class="number">0</span> || number &lt; min.getLast()) &#123;</span><br><span class="line">            min.addLast(number);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            min.addLast(min.getLast());</span><br><span class="line">        &#125;</span><br><span class="line">        mq.addLast(number);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * @return: An integer</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">pop</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">// write your code here</span></span><br><span class="line">        min.removeLast();</span><br><span class="line">        <span class="keyword">return</span> mq.removeLast();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * @return: An integer</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">min</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">// write your code here</span></span><br><span class="line">        <span class="keyword">return</span> min.getLast();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="7-骰子求和"><a href="#7-骰子求和" class="headerlink" title="7. 骰子求和"></a>7. 骰子求和</h3><p>扔 n 个骰子，向上面的数字之和为 S。给定 Given n，请列出所有可能的 S 值及其相应的概率。</p>
<p>这个排列组合和 <strong>提及数字计算数字k在0到n中的出现的次数，k可能是0~9的一个数值</strong> 很像，这题的思路就是通过投掷两个骰子去推算三个骰子的情况，和2题相同的思想，排列组合的区间覆盖，（梯度的覆盖，慢慢回想）</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>&#123;</span><br><span class="line">    <span class="keyword">public</span> List&lt;Map.Entry&lt;Integer, Double&gt;&gt; dicesSum(<span class="keyword">int</span> n) &#123;</span><br><span class="line">        <span class="keyword">double</span>[] dp = <span class="keyword">new</span> <span class="keyword">double</span>[n * <span class="number">6</span> + <span class="number">1</span>];</span><br><span class="line">        dp[<span class="number">0</span>] = <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a = <span class="number">1</span>; a &lt;= n; a++) &#123;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> b = a * <span class="number">6</span>; b &gt;= a; b--) &#123;</span><br><span class="line">                <span class="keyword">int</span> start = <span class="number">1</span>;</span><br><span class="line">                start = b - <span class="number">6</span> &gt;= a-<span class="number">1</span> ? b - <span class="number">6</span> : a-<span class="number">1</span>;</span><br><span class="line">                <span class="keyword">int</span> end = start+<span class="number">5</span>&gt;(a-<span class="number">1</span>)*<span class="number">6</span>?(a-<span class="number">1</span>)*<span class="number">6</span>:start+<span class="number">5</span>&gt;=b?b-<span class="number">1</span>:start+<span class="number">5</span>;</span><br><span class="line">                <span class="keyword">double</span> all = <span class="number">0</span>;</span><br><span class="line">                <span class="keyword">while</span> (start &lt;= end) &#123;</span><br><span class="line">                    all += dp[start];</span><br><span class="line">                    start++;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (a != <span class="number">1</span>) &#123;</span><br><span class="line">                    dp[b] = all;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    dp[b] = <span class="number">1</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        ArrayList&lt;Map.Entry&lt;Integer, Double&gt;&gt; needlist = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        <span class="keyword">double</span> all= Math.pow(<span class="number">6</span>, n);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> a = n; a &lt;= <span class="number">6</span> * n; a++) &#123;</span><br><span class="line">            AbstractMap.SimpleEntry&lt;Integer, Double&gt; entry = <span class="keyword">new</span> AbstractMap.SimpleEntry&lt;Integer, Double&gt;(a, dp[a] /all);</span><br><span class="line">            needlist.add(entry);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> needlist;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="8-最大子数组"><a href="#8-最大子数组" class="headerlink" title="8. 最大子数组"></a>8. 最大子数组</h3><p>没什么好说的高级DP，max[k个数组][n列]=max(max[k][n-1],max[k-1][n-1]+item[n])</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> nums: A list of integers</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> k: An integer denote to find k non-overlapping subarrays</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span>: An integer denote the sum of max k non-overlapping subarrays</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">maxSubArray</span><span class="params">(<span class="keyword">int</span>[] nums, <span class="keyword">int</span> k)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// write your code here</span></span><br><span class="line">        <span class="keyword">int</span>[][] singleMax = <span class="keyword">new</span> <span class="keyword">int</span>[k + <span class="number">1</span>][nums.length + <span class="number">1</span>];</span><br><span class="line"><span class="comment">//        表示j个数，i个子数组的最大和，必须包含第j个数</span></span><br><span class="line">        <span class="keyword">int</span>[][] max = <span class="keyword">new</span> <span class="keyword">int</span>[k + <span class="number">1</span>][nums.length + <span class="number">1</span>];</span><br><span class="line"><span class="comment">//        表示j个数，i个子数组的最大和，可以不包含第j个数</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= k; i++) &#123;</span><br><span class="line"><span class="comment">//            要分成i个子数组，最小得有i个数</span></span><br><span class="line">            singleMax[i][i - <span class="number">1</span>] = Integer.MIN_VALUE;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = i; j &lt;= nums.length; j++) &#123;</span><br><span class="line"><span class="comment">//                包含第j个数的最大值，是它和前边一起组成始数组或者它单独成为子数组的大的那个</span></span><br><span class="line">                singleMax[i][j] = Math.max(singleMax[i][j - <span class="number">1</span>], max[i - <span class="number">1</span>][j - <span class="number">1</span>]) + nums[j - <span class="number">1</span>];</span><br><span class="line">                <span class="keyword">if</span> (i == j) &#123;</span><br><span class="line">                    max[i][j] = singleMax[i][j];</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    max[i][j] = Math.max(singleMax[i][j], max[i][j - <span class="number">1</span>]);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> max[k][nums.length];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/详解http协议-基础概念/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/详解http协议-基础概念/" itemprop="url">未命名</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:22:37+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="http协议的基本流程"><a href="#http协议的基本流程" class="headerlink" title="http协议的基本流程"></a>http协议的基本流程</h3><p><img src="/blogimg/http/1.png" alt=""></p>
<h3 id="url和uri"><a href="#url和uri" class="headerlink" title="url和uri"></a>url和uri</h3><ol>
<li>url：统一资源标识符-表示一个网络地址</li>
<li>uri：统一资源定位符，表示互联网上的一个资源，使用的url是uri的一部分（http），其他相关的比如ftp等</li>
</ol>
<h3 id="http协议的特点"><a href="#http协议的特点" class="headerlink" title="http协议的特点"></a>http协议的特点</h3><p><strong>基于请求和响应一次请求必定跟随一次相应,无状态，可以使用cookie和session技术让状态有响应</strong></p>
<h3 id="http协议支持的请求头"><a href="#http协议支持的请求头" class="headerlink" title="http协议支持的请求头"></a>http协议支持的请求头</h3><p><img src="/blogimg/http/2.png" alt=""></p>
<h3 id="http1-1性能提升"><a href="#http1-1性能提升" class="headerlink" title="http1.1性能提升"></a>http1.1性能提升</h3><blockquote>
<p>持久链接：之前的http协议都是一次请求创建一次tcp链接，1.1升级为创建一次多次tcp请求</p>
</blockquote>
<p><img src="/blogimg/http/3.png" alt=""></p>
<blockquote>
<p>管线化：让http请求可以进行异步操作</p>
</blockquote>
<h3 id="http协议报文结构"><a href="#http协议报文结构" class="headerlink" title="http协议报文结构"></a>http协议报文结构</h3><p><img src="/blogimg/http/4.png" alt=""></p>
<ol>
<li>压缩传输内容：将传输的的报文实体使用gzip的方法进行压缩然后在发送出去</li>
<li>分块传输编码：降低出错重传的代价，使用16位进行块标识，最后一个块标识为”0(CR+LF)”</li>
</ol>
<h3 id="与http协作的web服务器"><a href="#与http协作的web服务器" class="headerlink" title="与http协作的web服务器"></a>与http协作的web服务器</h3><p><strong>（1）代理</strong></p>
<p><img src="/blogimg/http/5.png" alt=""></p>
<ul>
<li>作用：接受请求并转发个响应的其他请求</li>
<li>优势：利用缓存减少带宽，流量控制，访问日志</li>
</ul>
<p><strong>（2）网关</strong></p>
<p><img src="/blogimg/http/6.png" alt=""></p>
<ul>
<li>相当于升级http请求，转化成其它协议</li>
</ul>
<p><strong>（3）隧道</strong></p>
<p><img src="/blogimg/http/7.png" alt=""></p>
<ul>
<li>不进行协议解析直接进行信息转化</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/10/09/深入理解mybatis（四）动态sql/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="kyssion">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="kyssion-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/10/09/深入理解mybatis（四）动态sql/" itemprop="url">未命名</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-09T15:22:37+08:00">
                2018-10-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="深入理解mybatis（四）动态sql"><a href="#深入理解mybatis（四）动态sql" class="headerlink" title="深入理解mybatis（四）动态sql"></a>深入理解mybatis（四）动态sql</h2><p>通常使用动态 SQL 不可能是独立的一部分,MyBatis 当然使用一种强大的动态 SQL 语言来改进这种情形,这种语言可以被用在任意的 SQL 映射语句中。</p>
<p>MyBatis 3 大大提升了它们,现在用不到原先一半的元素就可以了。MyBatis 采用功能强大的基于 OGNL 的表达式来消除其他元素。</p>
<ul>
<li>if</li>
<li>choose (when, otherwise)</li>
<li>trim (where, set)</li>
<li>foreach</li>
</ul>
<hr>
<blockquote>
<p>引申:ognl表达式介绍</p>
</blockquote>
<p>MyBatis常用OGNL表达式</p>
<ul>
<li>e1 or e2</li>
<li>e1 and e2</li>
<li>e1 == e2,e1 eq e2</li>
<li>e1 != e2,e1 neq e2</li>
<li>e1 lt e2：小于</li>
<li>e1 lte e2：小于等于，其他gt（大于）,gte（大于等于）</li>
<li>e1 in e2</li>
<li>e1 not in e2</li>
<li>e1 + e2,e1 * e2,e1/e2,e1 – e2,e1%e2</li>
<li>!e,not e：非，求反</li>
<li>e.method(args)调用对象方法</li>
<li>e.property对象属性值</li>
<li>e1[ e2 ]按索引取值，List,数组和Map</li>
<li>@class@method(args)调用类的静态方法</li>
<li>@class@field调用类的静态字段值</li>
</ul>
<blockquote>
<p>mybatis中的# 和 $</p>
</blockquote>
<p>‘#’会将字符串进行转译</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">#&#123;property,javaType=int,jdbcType=NUMERIC&#125;</span><br><span class="line">#&#123;age,javaType=int,jdbcType=NUMERIC,typeHandler=MyTypeHandler&#125; //指定类型处理器</span><br><span class="line">#&#123;height,javaType=double,jdbcType=NUMERIC,numericScale=2&#125; //指定保留位数</span><br></pre></td></tr></table></figure>
<p>‘$’直接进行字符串替换</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ORDER BY $&#123;columnName</span><br></pre></td></tr></table></figure>
<hr>
<h3 id="if-关键字"><a href="#if-关键字" class="headerlink" title="if 关键字"></a>if 关键字</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findActiveBlogLike"</span></span></span><br><span class="line"><span class="tag">     <span class="attr">resultType</span>=<span class="string">"Blog"</span>&gt;</span></span><br><span class="line">  SELECT * FROM BLOG WHERE state = ‘ACTIVE’ </span><br><span class="line">  <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"title != null"</span>&gt;</span></span><br><span class="line">    AND title like #&#123;title&#125;</span><br><span class="line">  <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"author != null and author.name != null"</span>&gt;</span>  <span class="comment">&lt;!--使用ognl表达式--&gt;</span></span><br><span class="line">    AND author_name like #&#123;author.name&#125;</span><br><span class="line">  <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="choose-when-otherwise-关键字"><a href="#choose-when-otherwise-关键字" class="headerlink" title="choose, when, otherwise  关键字"></a>choose, when, otherwise  关键字</h3><p>相当于java中的switch语句</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findActiveBlogLike"</span></span></span><br><span class="line"><span class="tag">     <span class="attr">resultType</span>=<span class="string">"Blog"</span>&gt;</span></span><br><span class="line">  SELECT * FROM BLOG WHERE state = ‘ACTIVE’</span><br><span class="line">  <span class="tag">&lt;<span class="name">choose</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">when</span> <span class="attr">test</span>=<span class="string">"title != null"</span>&gt;</span></span><br><span class="line">      AND title like #&#123;title&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">when</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">when</span> <span class="attr">test</span>=<span class="string">"author != null and author.name != null"</span>&gt;</span></span><br><span class="line">      AND author_name like #&#123;author.name&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">when</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">otherwise</span>&gt;</span></span><br><span class="line">      AND featured = 1</span><br><span class="line">    <span class="tag">&lt;/<span class="name">otherwise</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">choose</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="trim-where-set-关键字"><a href="#trim-where-set-关键字" class="headerlink" title="trim, where, set 关键字"></a>trim, where, set 关键字</h3><p>解决拼接字符串的时候，where and 等字段多余的问题</p>
<p>比如这样的语句</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findActiveBlogLike"</span></span></span><br><span class="line"><span class="tag">     <span class="attr">resultType</span>=<span class="string">"Blog"</span>&gt;</span></span><br><span class="line">  SELECT * FROM BLOG </span><br><span class="line">  WHERE </span><br><span class="line">  <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"state != null"</span>&gt;</span></span><br><span class="line">    state = #&#123;state&#125;</span><br><span class="line">  <span class="tag">&lt;/<span class="name">if</span>&gt;</span> </span><br><span class="line">  <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"title != null"</span>&gt;</span></span><br><span class="line">    AND title like #&#123;title&#125;</span><br><span class="line">  <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"author != null and author.name != null"</span>&gt;</span></span><br><span class="line">    AND author_name like #&#123;author.name&#125;</span><br><span class="line">  <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>如果这些条件没有一个能匹配上，最终的结果竟会变成这样</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM BLOG WHERE</span><br></pre></td></tr></table></figure>
<p>使用where标签包裹将会解决这个问题</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findActiveBlogLike"</span></span></span><br><span class="line"><span class="tag">     <span class="attr">resultType</span>=<span class="string">"Blog"</span>&gt;</span></span><br><span class="line">  SELECT * FROM BLOG </span><br><span class="line">  <span class="tag">&lt;<span class="name">where</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"state != null"</span>&gt;</span></span><br><span class="line">         state = #&#123;state&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">if</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"title != null"</span>&gt;</span></span><br><span class="line">        AND title like #&#123;title&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"author != null and author.name != null"</span>&gt;</span></span><br><span class="line">        AND author_name like #&#123;author.name&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">where</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>类似的 trim 相比 where 只是多了定制属性</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">trim</span> <span class="attr">prefix</span>=<span class="string">"where"</span> <span class="attr">prefixOverrides</span>=<span class="string">""</span> <span class="attr">suffix</span>=<span class="string">""</span> <span class="attr">suffixOverrides</span>=<span class="string">""</span>&gt;</span><span class="tag">&lt;/<span class="name">trim</span>&gt;</span></span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th></th>
<th>参数</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>prefix</td>
<td>指定包裹块生成sql之后要添加的前缀</td>
</tr>
<tr>
<td>prefixOverrides</td>
<td>忽略第一个指定的标识符，可以使用</td>
<td>表示多个语句</td>
</tr>
<tr>
<td>suffix</td>
<td>指定包裹块生成sql之后要添加的后缀</td>
</tr>
<tr>
<td>suffixOverrides</td>
<td>忽略最后一个指定的标识符，可以使用</td>
<td>表示多个语句</td>
</tr>
</tbody>
</table>
<p>set语句一般用在进行动态添加列属性</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">update</span> <span class="attr">id</span>=<span class="string">"updateAuthorIfNecessary"</span>&gt;</span></span><br><span class="line">  update Author</span><br><span class="line">    <span class="tag">&lt;<span class="name">set</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"username != null"</span>&gt;</span>username=#&#123;username&#125;,<span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"password != null"</span>&gt;</span>password=#&#123;password&#125;,<span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"email != null"</span>&gt;</span>email=#&#123;email&#125;,<span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">"bio != null"</span>&gt;</span>bio=#&#123;bio&#125;<span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">set</span>&gt;</span></span><br><span class="line">  where id=#&#123;id&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">update</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="foreach"><a href="#foreach" class="headerlink" title="foreach"></a>foreach</h3><p>动态 SQL 的另外一个常用的必要操作是需要对一个集合进行遍历，通常是在构建 IN 条件语句的时候。比如：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"selectPostIn"</span> <span class="attr">resultType</span>=<span class="string">"domain.blog.Post"</span>&gt;</span></span><br><span class="line">  SELECT *</span><br><span class="line">  FROM POST P</span><br><span class="line">  WHERE ID in</span><br><span class="line">  <span class="tag">&lt;<span class="name">foreach</span> <span class="attr">item</span>=<span class="string">"item"</span> <span class="attr">index</span>=<span class="string">"index"</span> <span class="attr">collection</span>=<span class="string">"list"</span></span></span><br><span class="line"><span class="tag">      <span class="attr">open</span>=<span class="string">"("</span> <span class="attr">separator</span>=<span class="string">","</span> <span class="attr">close</span>=<span class="string">")"</span>&gt;</span></span><br><span class="line">        #&#123;item&#125;</span><br><span class="line">  <span class="tag">&lt;/<span class="name">foreach</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>foreach 元素的功能是非常强大的，它允许你指定一个集合，声明可以用在元素体内的集合项和索引变量。它也允许你指定开闭匹配的字符串以及在迭代中间放置分隔符。这个元素是很智能的，因此它不会偶然地附加多余的分隔符。</p>
<p><strong>注意</strong>：你可以将任何可迭代对象（如列表、集合等）和任何的字典或者数组对象传递给foreach作为集合参数。当使用可迭代对象或者数组时，index是当前迭代的次数，item的值是本次迭代获取的元素。当使用字典（或者Map.Entry对象的集合）时，index是键，item是值。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><span class="space">&hellip;</span><a class="page-number" href="/page/14/">14</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">kyssion</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">133</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">kyssion</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
